在一个表中,我要确保五列键上仅存在唯一值:
Timestamp Account RatingDate TripHistoryKey EventAction
========= ======= ========== ============== ===========
2010511 1234 2010511 1 INSERT
2010511 1234 2010511 4 INSERT
2010511 1234 2010511 7 INSERT
2010511 1234 2010511 1 INSERT <---duplicate
但是我只希望事件操作为
INSERT
时在行之间应用唯一约束:Timestamp Account RatingDate TripHistoryKey EventAction
========= ======= ========== ============== ===========
2010511 1234 2010511 1 INSERT
2010511 1234 2010511 1 UPDATE
2010511 1234 2010511 1 UPDATE <---not duplicate
2010511 1234 2010511 1 UPDATE <---not duplicate
2010511 1234 2010511 1 DELETE <---not duplicate
2010511 1234 2010511 1 DELETE <---not duplicate
2010511 1234 2010511 1 INSERT <---DUPLICATE
可能?
最佳答案
是
SQL Server 2008:使用筛选索引
SQL Server 2005:使用触发器或索引视图
编辑:
Indexed view example