22.4. Global Constants Tables

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;

The lock column ensures that there is only one row, and the default values load the initial values. These defaults can include the current user and current ...

Get Joe Celko's SQL for Smarties, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.