Create default constraint with the check for existence in sql server

if not exists
(
select    null
from    sys.objects
where    type_Desc = N’DEFAULT_CONSTRAINT’
and object_name(parent_object_id) = N’Product’
and object_name(object_id) = N’DF_Product_ByInstance’
)
begin
alter table Product
add constraint DF_Product_ByInstance default 0 for ByInstance
end
go

Advertisements