1

Recently I set value for Default Value or Binding to (newid()) in table design.

Now I want to generate scripts for the changes to execute on another database.

Can anyone please help me to write/generate script for these changes.

Thanks in advance!

Note: I have checked this solution but not helped me coz I want to generate script for all the tables in which I have made changes recently for Default Value or Binding

1

1 Answer 1

3

Use the below query to generate the script for default constraints with default value newid()

SELECT 'alter table ' + Quotename(o.name)
       + ' add constraint ' + Quotename(dc.name)
       + ' default ' + dc.definition + ' for '
       + Quotename(c.name)
FROM   sys.default_constraints dc
       INNER JOIN sys.columns c
               ON dc.parent_object_id = c.object_id
                  AND dc.parent_column_id = c.column_id
       INNER JOIN sys.objects o
               ON o.object_id = dc.parent_object_id
WHERE  definition = '(newid())' 

copy paste the result in new database and execute it create the default constraints.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.