SQL - Foreign Key(外键)
-
简述
外键是用于将两个表链接在一起的键。这有时也称为引用键。外键是其值与不同表中的主键匹配的列或列组合。The relationship between 2 tables matches the Primary Key in one of the tables with a Foreign Key in the second table.如果表在任何字段上定义了主键,则不能有两条记录具有该字段的相同值。例子
考虑以下两个表的结构。CUSTOMERS tableORDERS table如果已经创建了 ORDERS 表并且尚未设置外键,则使用通过更改表来指定外键的语法。 -
删除外键约束
要删除 FOREIGN KEY 约束,请使用以下 SQL 语法。