Declarative Defaults
A declarative default is a constraint defined as part of the table definition. Using declarative defaults is the preferred method for assigning default values to columns. You can use the CREATE TABLE
or ALTER TABLE
statement to create a default and assign it to a column. Declarative defaults are assigned to a single column and cannot be reused for other columns in the database. The following example shows the creation of a new column namedCustomerType
in the SalesCustomer
table followed by the creation of a new default on that column:
ALTER TABLE Sales.Customer ADD CustomerType CHAR(1)ALTER TABLE Sales.Customer ADD CONSTRAINT DF_Customer_CustomerType DEFAULT 'I' FOR CustomerType
It is important ...
Get Microsoft® SQL Server 2012 Unleashed now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.