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.

Keith
  • 20,636
  • 11
  • 84
  • 125
marapet
  • 54,856
  • 12
  • 170
  • 184

1 Answers1

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
Peter Schott
  • 4,521
  • 21
  • 30