MySQL ใช้ Foreign Key Constraint แทนการสืบทอด (inheritance) MySQL ไม่รองรับ Table Inheritance โดยตรง
แต่สามารถทำได้ผ่าน Foreign Key มาสร้างตาราง:
ตารางแม่ (Parent)
mysql> create table Parent_Table ( ParentId int, PRIMARY KEY(ParentId) ); Query OK, 0 rows affected (3.59 sec)
ตารางลูก (Child)
mysql> create table Child_Table ( ChildId int references Parent_Table, PRIMARY KEY(ChildId) ); Query OK, 0 rows affected (0.73 sec)
เพิ่ม Foreign Key constraint:
mysql> alter table Child_Table add constraint FK_Child Foreign key(ChildId) references Parent_Table(ParentId); Query OK, 0 rows affected (2.28 sec) Records: 0 Duplicates: 0 Warnings: 0