July 2010
Intermediate to advanced
840 pages
16h 33m
English
One of the most popular uses for the IN() predicate is in a CHECK() clause on a table. The usual form is a list of values that are legal for a column, such 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 (state_code IN ('AL', 'AK', ...)),
...);This method works fine with a small list of values, but it has problems with a longer list. It is very important to arrange the values in the order that they are most likely to match to the two-letter state_code to speed up the search.
In Standard SQL a constraint can reference other tables, so you could write ...
Read now
Unlock full access