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

Advertisements