if not exists (
    select 1 from sys.default_constraints cs
        join sys.all_columns c on c.column_id = cs.parent_column_id and cs.parent_object_id = c.object_id
    where parent_object_id = OBJECT_ID('IES.T_SCHET_ACT_ITEM')
            and
        c.name = 'ByMEK'
)
begin
    alter table IES.T_SCHET_ACT_ITEM
    add constraint DF_T_SCHET_ACT_ITEM_ByMEK default 0 for ByMEK;
end

if exists (
    select 1 from information_schema.columns
    where TABLE_SCHEMA = 'IES'
    and TABLE_NAME = 'T_SCHET_ACT_ITEM'
    and COLUMN_NAME = 'ByMEK'
    and IS_NULLABLE = 'YES'
)
begin
    update IES.T_SCHET_ACT_ITEM
    set ByMEK = 0
    where ByMEK is null;

    alter table IES.T_SCHET_ACT_ITEM
    alter column ByMEK bit not null;
end
