Newer
Older
labs / tiddlers / content / labs / lab03 / _Labs_03_Column Values_ Mandatory and Default.md
@Gary Burrows Gary Burrows on 22 Jul 866 bytes Lab03 upload

Mandatory Column Values

Columns that are required to have a value (indicated by • in the ERD) should have a NOT NULL constraint applied, following the data type, like so:

    Sale_Date timestamp not null,

Default Column Values

Sometimes a column has a sensible default value, which the system can insert automatically if the user does not specify one. These can be a fixed value such as a default bank balance of 0, or a calculation such as using the current date and time for new sales.

To define a default column value, use the DEFAULT keyword followed by the desired expression. This must appear after the data type for the column, but before any constraints such as NOT NULL.

Sale_Date timestamp default current_timestamp not null,

Update your DDL to match the requirements for mandatory values in the ERD.