SQL Database Design » 9. Default Values » 9.1 Simple Defaults

9.1 Simple Defaults

Default values are what they are: defaults when nothing else is specified. The DEFAULT clause can only be specified inline (see the 10. Constraints section). Whereever defaults are set, you can omit passing a value into the INSERT INTO statement. Simple defaults can also be used in foreign key constraints to fall back to a specific value when a SET DEFAULT is executed.

The SQL standard defines a fixed order for defaults and constraints: the default clause must be specified before the constraints. Thus, the code points SMALLINT NOT NULL DEFAULT 0 would syntactically be wrong according to the SQL standard. However, most DBMSs allow any order. HSQLDB and Firebird are noteworthy exceptions which generate an error on non-standard default order.

Last updated: 2010-11-10