TSQL foreign keys on views?

后端 未结 11 1090
臣服心动
臣服心动 2021-01-01 13:51

I have a SQL-Server 2008 database and a schema which uses foreign key constraints to enforce referential integrity. Works as intended. Now the user creates views on the orig

11条回答
  •  佛祖请我去吃肉
    2021-01-01 14:27

    If rolling over tables so that Identity columns will not clash, one possibility would be to use a lookup table that referenced the different data tables by Identity and a table reference.

    Foreign keys on this table would work down the line for referencing tables.

    This would be expensive in a number of ways Referential integrity on the lookup table would have to be be enforced using triggers. Additional storage of the lookup table and indexing in addition to the data tables. Data reading would almost certainly involve a Stored Procedure or three to execute a filtered UNION. Query plan evaluation would also have a development cost.

    The list goes on but it might work on some scenarios.

提交回复
热议问题