我们能否在单个表中创建外键 [英] Can we able to create foreign key in a single table

查看:161
本文介绍了我们能否在单个表中创建外键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友,

我们可以在一个表中创建外键吗?


我有一张学生桌.它包含列,如sid,sfirstname,slastname,saddress和sno.在此表中,sid是主键.我想将sno作为引用sid的外键.




在此先感谢

Dear friends,

Can we able to create foreign key in one table


I have a student table. It contains columns as sid,sfirstname,slastname,saddress and sno. In this table sid is the primary key. I want to make sno as foreign key which references to sid.




Thanks in advance

推荐答案

外键是在其他表上定义的,而不是在同一表上定义的,除非您想建立自引用链接,例如Employee.ManagedBy-> Employee.pid
Foreign keys are defined on other tables, not on the same table unless you want to make self referencing links e.g. Employee.ManagedBy --> Employee.pid


有可能!在此处阅读: http://en.wikipedia.org/wiki/Foreign_key [
It is possible! Read here: http://en.wikipedia.org/wiki/Foreign_key[^]. What you are trying to do is known as a self-referencing or recursive foreign key.

Best Regards,

—MRB


这篇关于我们能否在单个表中创建外键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆