Search code examples
sql-serverviewforeign-keys

Can I have a foreign key referencing a column in a view in SQL Server?


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)

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?


Solution

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