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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s