Create a check constraint in sql server

if not exists
(
select    null
from    sys.objects
where    type_Desc = N’CHECK_CONSTRAINT’
and object_name(parent_object_id) = N’Product’
and object_name(object_id) = N’CK_Product_Constraint’
)
begin
alter table Product
add constraint CK_Product_Constraint check (not(ByInstance = 1 and stock_avail_id <> 1))
end
go

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