地址表爲兩個公司和聯繫人共享。我有一個限制,阻止用戶添加公司ID和聯繫人ID的記錄。我試圖添加另一個約束,使每個公司ID或聯繫人ID只有1個活動(ACTIVE FLAG ='TRUE')地址。但我希望能夠無限制地無效(ACTIVE FLAG ='FALSE')。每個ID一個有效記錄
ALTER TABLE [dbo].[ADDRESSES] WITH CHECK ADD CONSTRAINT [chk_ONLY_ONE_ACTIVE_ADDRESS] CHECK (([COMPANY_ID] IS NOT NULL AND [CONTACT_ID] IS NULL AND [ACTIVE] = 'TRUE' OR [COMPANY_ID] IS NULL AND [CONTACT_ID] IS NOT NULL AND [ACTIVE] = 'TRUE' OR [COMPANY_ID] IS NULL AND [CONTACT_ID] IS NOT NULL AND [ACTIVE] = 'FALSE' OR [COMPANY_ID] IS NOT NULL AND [CONTACT_ID] IS NULL AND [ACTIVE] = 'FALSE'))
GO
我在哪裏錯過了?
感謝 jlimited