Include default constraint names in generation of update script
Asked Answered
A

1

7

I'm using a SQL Server Database Project with Visual Studio 2012 and have the following problem when comparing and generating an update script:

In Visual Studio, I add a column with a default constraint, for example:

[NewColumn] NVARCHAR(50) CONSTRAINT [DF_ExistingTable_NewColumn] NOT NULL DEFAULT N''

Unfortunately, the name of the default constraint does not appear when:

  • Comparing (Schema Compare) my project with the actual database
  • Generating an update script (from within the Schema Compare)

The created update script contains the following script (no constraint name):

ALTER TABLE [dbo].[ExistingTable]
    ADD [NewColumn] NVARCHAR (50) DEFAULT N'' NOT NULL;

This seems like a major oversight, so I'm wondering where to find the magic switch to include the names of default constraints in all database operations.

Agglutinogen answered 31/10, 2012 at 16:28 Comment(0)
Z
5

I think the order may be off in your definition. Try moving the "NOT NULL" part to the end of the line instead of in the middle of your constraint definition.

[NewColumn] NVARCHAR(50) CONSTRAINT [DF_ExistingTable_NewColumn] DEFAULT N'' NOT NULL
Ziguard answered 1/5, 2013 at 14:42 Comment(1)
I just did the same mistake. Thanks, NOT NULL must obviously be in the end.Ravenous

© 2022 - 2025 — McMap. All rights reserved.