When a Default Is Applied
Defaults are applied only when no value is specified for a column during an insertion. They can also be applied during insertions and updates when the DEFAULT
keyword is used. To demonstrate the application of defaults, consider the following examples:
CREATE TABLE test_default(id int IDENTITY NOT NULL, tmstmp timestamp NOT NULL, password char(13) NOT NULL DEFAULT 'defaultpw', Shortdesc VARCHAR(50) NULL)
The table in this example has a unique characteristic: each column has some sort of default value associated with it. One column has a default of NULL
because it is nullable. The IDENTITY
and TIMESTAMP
columns automatically generate values because of their data type, and the password column ...
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.