Multiple column foreign key contraints

后端 未结 5 1687
你的背包
你的背包 2020-12-02 00:40

I want to setup table constraints for the following scenario and I’m not sure how to do it or if it’s even possible in SQL Server 2005.

I have three tables A,B,C. C

5条回答
  •  情深已故
    2020-12-02 01:08

    Looks like the common ues case for you is you have A's key and you need all the matching rows in C. In which case the following query should be fast:

    select C.* 
    from B
    join C on C.Bid = B.Bid
    where C.Aid = 
    

    with proper indexes this should be just as fast as if you have Aid on C because they will both require an index scan followed by joining that result to the C table.

提交回复
热议问题