LJ Archive

Listing 3. Using Referential Integrity Checks

CREATE TABLE People (''
  person_id  SERIAL      NOT NULL,

  name      VARCHAR(40) NOT NULL  CHECK (name <> ''),
  address1  VARCHAR(30) NULL      CHECK (address1 <> ''),
  address2  VARCHAR(30) NULL      CHECK (address2 <> ''),
  email     VARCHAR(50) NOT NULL  CHECK (email ~ '@'),
  city      VARCHAR(30) NULL      CHECK (city <> ''),
  state     VARCHAR(2)  NULL      CHECK (state <> ''),
  zip       VARCHAR(10) NULL      CHECK (zip <> ''),

  PRIMARY KEY(person_id),
  UNIQUE(name)
);
LJ Archive