我可以有一个外键引用 SQL Server 视图中的列吗?

2021-12-29 00:00:00 foreign-keys sql-server view

在 SQL Server 2008 中并给出

In SQL Server 2008 and given

TableA(A_ID, A_Data)
TableB(B_ID, B_Data)
ViewC(A_or_B_ID, A_or_B_Data)

是否可以定义 TableZ(A_or_B_ID, Z_Data) 使得 Z.A_or_B_ID 列被限制为在 ViewC 中找到的值?这可以通过针对视图的外键来完成吗?

is it possible to define TableZ(A_or_B_ID, Z_Data) such that Z.A_or_B_ID column is constrained to the values found in ViewC? Can this be done with a foreign key against the view?

推荐答案

不能在外键中引用视图.

You can't reference a view in a foreign key.

相关文章