Generate Table Scripts

  • I am trying to script tables using Generate Scripts Wizard. but the script which is created does not have default constraints written to it even though "Script Defaults" is set to True. Any idea why default constraints are not being written to the file.

    Any help on this would be grateful. Thanks.

  • Right click the table and select "Script table as" > "Create to" > "New query editor window".

    Do you see the default constraint script there?

    Please post results of the following query

    SELECTdc.nameAS ConstraintName

    , dc.definitionAS ConstraintDefinition

    , dc.type_descAS ConstraintType

    , c.nameAS ColumnName

    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

    WHERE OBJECT_NAME(c.object_id) = 'yourtablename'

    -----------------------------------------------------------------------------------------------------------

    "Ya can't make an omelette without breaking just a few eggs" 😉

  • there are a lot of options for scripting that can be enabled/disabled;

    take a look in your Tools>>Options (in 2012 SSMS, it's Tools>>Options>>SQL Server Object Explorer>>Scripting

    and check your setting for "Script defaults"

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply