Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Include default constraint names in generation of update script

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.

like image 758
marapet Avatar asked Oct 31 '12 16:10

marapet


1 Answers

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
like image 191
Peter Schott Avatar answered Sep 20 '22 17:09

Peter Schott