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

前端 未结 7 1997
难免孤独
难免孤独 2020-12-01 15:34

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(

7条回答
  •  半阙折子戏
    2020-12-01 16:09

    Sorry, In the strict sense of the word, no you cannot set foreign keys on views. Here is why:

    InnoDB is the only built-in storage engine for MySQL that features foreign keys. Any InnoDB table will be registered in information_schema.tables with engine = 'InnoDB'.

    Views, while registered in information_schema.tables, has a NULL storage engine. There are no mechanisms in MySQL to have foreign keys on any table that has an undefined storage engine.

    Thanks!

提交回复
热议问题