July 2010
Intermediate to advanced
840 pages
16h 33m
English
Standard SQL was designed so that the declarative referential constraints could be expressed as EXISTS() predicates in a CHECK() clause. For example:
CREATE TABLE Addresses
(addressee_name CHAR(25) NOT NULL PRIMARY KEY,
street_loc CHAR(25) NOT NULL,
city_name CHAR(20) NOT NULL,
state_code CHAR(2) NOT NULL
REFERENCES ZipCodeData(state_code),
...);could be written as:
CREATE TABLE Addresses
(addressee_name CHAR(25) NOT NULL PRIMARY KEY,
street_loc CHAR(25) NOT NULL,
city_name CHAR(20) NOT NULL,
state_code CHAR(2) NOT NULL,
CONSTRAINT valid_state_code
CHECK (EXISTS(SELECT *
FROM ZipCodeData AS Z1
WHERE Z1.state_code = Addresses.state_code)),
...);There is no advantage to this expression for the DBA, ...
Read now
Unlock full access