January 2008
Intermediate to advanced
384 pages
8h 1m
English
When you configure a system, you might want to have a way to set and keep constants in the schema. One method for doing this is to have a one-row table that can be set with default values at the start, and then updated only by someone with administrative privileges.
CREATE TABLE Constants
(lock CHAR(1) DEFAULT 'X'
NOT NULL PRIMARY KEY
CHECK (lock = 'X'),
pi FLOAT DEFAULT 3.142592653 NOT NULL,
e FLOAT DEFAULT 2.71828182 NOT NULL,
phi FLOAT DEFAULT 1.6180339887 NOT NULL,
..);To initialize the row, execute this statement:
INSERT INTO Constants VALUES DEFAULTS;
Most SQL programmers do not know about the VALUES DEFAULTS option in the INSERT INTO statement. The lock column ensures there is only one row and the DEFAULT values load ...
Read now
Unlock full access