外键约束的本质就是增加数据的可重复利用性。也就是说假如我们有一个省份的表:P表,这个表里存储着中国34个省份名称并且有唯一编号约束(比方说1.河南省 2.四川省 3.广东省 4.吉林省……);现在有个统计各省GDP的表A,有个统计人籍贯的表B,还有一个统计各省人口的表C。如果把各省的名字再输入一遍的话那就需要输入4遍省份的名字,这种工作像评论区有些手插在裤裆里不动手操作还骂老师教的不好的人肯定会觉得很麻烦;为了这些人,MySQL发明了一个非常牛逼的方法:从那个P表里把个省份的序号直接引用过来分别填在A、B、C表中,这样P表中的信息就被A、B、C三个表给共享了,就达到了一次输入,永久使用的目的。












网友评论