Example 1
ISO 5218 sex codes.
Small in number (only four possible values). Are considered stable (not much chance of a new sex being discovered and why change the standard?) Therefore, a SWITCH()
statement would be appropriate:
SELECT SWITCH(
C1.sex_code = 9, 'corporate body',
C1.sex_code = 1, 'male',
C1.sex_code = 2, 'female',
TRUE, '(not known)'
) AS customer_person_type, ...
FROM Customers AS C1 ...
Example 2
ISO 4217 currency codes.
Relatively large in number (approx 175). Are considered to be in flux (one clue is that it has an official agency responsible for maintenance). Therefore, these would be most appropriate in a base table:
CREATE TABLE Currencies
(
currency_code CHAR(3) NOT NULL,
CHECK (currency_code NOT ALIKE '%[!A-Z]%'),
currency_name VARCHAR(30) NOT NULL
);
INSERT INTO Currencies VALUES ('AED', 'United Arab Emirates dirham');
INSERT INTO Currencies VALUES ('AFN', 'Afghani');
INSERT INTO Currencies VALUES ('ALL', 'Lek');
INSERT INTO Currencies VALUES ...
So which is best for you: sex or currency? ;)