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 2014 Unleashed now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.