TSQL foreign keys on views?

后端 未结 11 1085
臣服心动
臣服心动 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

    You could stage the filtered table 1 data to another table. The contents of this staging table are your view 1, and then you build view 2 via a join of the staging table and table 2. This way the proccessing for filtering table 1 is done once and reused for both views.

    Really what it boils down to is that view 2 has no idea what kind of filtering you performed in view 1, unless you tell view 2 the filtering criteria, or make it somehow dependent on the results of view 1, which means emulating the same filtering that occurs on view1.

    Constraints don't perform any kind of filtering, they only prevent invalid data, or cascade key changes and deletes.

提交回复
热议问题