Name Your Defaults So SQL Server Doesn't
Something in SQL Server that isn’t always obvious to beginners is that when you create a default value for a column on a table, SQL Server creates a constraint (much like a primary or foreign key). All constraints must have a name, and if one isn’t specified SQL Server will generate one for you. For example:
|
|
We’ve got a simple table here and both fields have a default value set (the primary key’s value is generated from a sequence object, pointtypeid
). Time goes on, and a change in policy comes up which requires that I change the default value of typename
to Unknown
. To do this, I have to drop the constraint and re-create it. To find the name of the constraint, I can either ask sp_help
, or run this query: