1

I was having a looking on this article about default constraints and I have a question. Is there a configuration in SQL Server 2008 that forbid naming creation of new default constraints declared without a proper custom name?

In other words, can SQL Server block this:

CREATE TABLE Test1 (
   Val1 int DEFAULT -1, 
   Val2 int DEFAULT -2) 
  /*the fields above will generate a strange suffix in default constraint name such as DF__Test1__Val1__32E0915F*/

but allow this:

CREATE TABLE Test1 (
   Val1 int Test1_Val1_DF DEFAULT -1, 
   Val2 int Test1_Val2_DF DEFAULT -2) 
  /*the fields will use proper custom name in default constraint name*/
Junior Mayhe
  • 337
  • 1
  • 2
  • 12

1 Answers1

4

I think you could use a DDL trigger if you could build a reliable LIKE expression that determines that a column has been specified with a default but does not contain the word constraint before the word default. But that won't be very fun. If you don't have PBM you're probably better off just manually reviewing the DDL in the default trace or having a DDL trigger that e-mails you on create/alter table, and slapping wrists when it happens.

(I mean, how often are people creating tables in a way that violates your corporate naming standard, and why are they still allowed to create tables if they can't follow the rules?)

Aaron Bertrand
  • 181,950
  • 28
  • 405
  • 624