Script to script out the default constraints inĀ  a database:

 

select

'ALTER TABLE [' + SCHEMA_NAME(dc.schema_id) + '].[' +t.name + ']

ADD CONSTRAINT '+ dc.name +' DEFAULT ' + dc.definition +' FOR '+ c.name from sys.default_constraintsĀ  as dc

inner join sys.tables t

on dc.parent_object_id = t.object_id

inner join sys.columns c

on dc.parent_column_id = c.column_id

and dc.parent_object_id = c.object_id

Leave a Comment

Your email address will not be published. Required fields are marked *