Setting Default Values and NULL Status

From InterBase
Jump to: navigation, search

Go Up to Developing a Set of Rules (Designing Databases)

When you define a column, you have the option of setting a DEFAULT value. This value is used whenever an INSERT or UPDATE on the table does not supply an explicit value for the column. Defaults can save data entry time and prevent data entry errors. For example, a possible default for a DATE column could be today’s date; in a Y/N flag column for saving changes, “Y” could be the default. Column-level defaults override defaults set at the domain level. Some examples:

stringfld VARCHAR(10) DEFAULT ‘abc’
integerfld INTEGER DEFAULT 1
numfld NUMERIC(15,4) DEFAULT 1.5
datefld1 DATE DEFAULT ‘5/5/2005’

The last two lines show special InterBase features: ‘TODAY’ defaults to the current date, and USER is the user who is performing an insert to the column.

Assign a NULL default to insert a NULL into the column if the user does not enter a value. Assign NOT NULL to force the user to enter a value, or to define a default value for the column. NOT NULL must be defined for PRIMARY KEY and UNIQUE key columns.

Advance To: