gpt4 book ai didi

sql-server - SQL Server : "MoSTLy-unique" index

转载 作者:行者123 更新时间:2023-12-03 02:14:06 26 4
gpt4 key购买 nike

在表中,我想确保五列键上仅存在唯一值:

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

但是我只希望当EventActionINSERT时在行之间应用唯一约束:

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:使用触发器或索引 View

编辑:

关于sql-server - SQL Server : "MoSTLy-unique" index,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2821045/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com