Using foreign key as an enum type
mysql>
mysql> CREATE TABLE SEXES (SEX CHAR(1) NOT NULL PRIMARY KEY)
-> ;
Query OK, 0 rows affected (0.00 sec)
mysql> INSERT INTO SEXES VALUES ('M'),('F')
-> ;
Query OK, 2 rows affected (0.00 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql>
mysql> CREATE TABLE EmployeeS_SMALL2
-> (EmployeeNO INTEGER NOT NULL PRIMARY KEY,
-> NAME CHAR(15) NOT NULL,
-> INITIALS CHAR(3) NOT NULL,
-> BIRTH_DATE DATE,
-> SEX CHAR(1),
-> FOREIGN KEY (SEX) REFERENCES SEXES (SEX));
Query OK, 0 rows affected (0.00 sec)
mysql>
mysql>
mysql> drop table sexes;
ERROR 1217 (23000): Cannot delete or update a parent row: a foreign key constraint fails
mysql> drop table Employees_small2;
Query OK, 0 rows affected (0.00 sec)
Related examples in the same category