我们可以有一个不是任何其他表中的主键的外键吗? [英] can we have a foreign key which is not a primary key in any other table?

查看:19
本文介绍了我们可以有一个不是任何其他表中的主键的外键吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每本书都写外键实际上是其他表中的主键,但我们可以有一个不是任何其他表中的主键的外键

it is written in every book that foreign keys are actually primary key in some other table but can we have a foreign key which is not primary key in any other table

推荐答案

是的 - 您可以使用外键引用另一个表中的唯一索引.

Yes - you can have a foreign key that references a unique index in another table.

CREATE UNIQUE INDEX UX01_YourTable ON dbo.YourTable(SomeUniqueColumn)

ALTER TABLE dbo.YourChildTable
   ADD CONSTRAINT FK_ChildTable_Table
   FOREIGN KEY(YourFKColumn) REFERENCES dbo.YourTable(SomeUniqueColumn)

这篇关于我们可以有一个不是任何其他表中的主键的外键吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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