如何限制表某一字段除0值之外的数据不能有重复

sinman 2009-05-15 11:36:46
rt
...全文
103 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
mvp_chen 2009-06-05
  • 打赏
  • 举报
回复
等待更好的方案.
sinman 2009-05-15
  • 打赏
  • 举报
回复
表的业务量比较大,想过触发器,怕影响速度,不知道有没有更好的办法。程序无源码,无法修改,只能在数据库上做文章。
BILearner 2009-05-15
  • 打赏
  • 举报
回复
不好意思 忘记我把ID这个列删了 你创建的时候别把ID这个列创建进去,自己把上面的脚本修改一下做个存储过程,每次要插入前先运行一下 就是了!返回1就别插入 返回0就插入!
BILearner 2009-05-15
  • 打赏
  • 举报
回复
Create table test
(id int,Score int)

Insert into test
select 100
union all select 0
union all select 0
union all select 100
union all select 80

declare @score int

Select Score,count(1) From test
where score=@Score
group by Score
having count(1)>1 and sum(score)<>0
百年树人 2009-05-15
  • 打赏
  • 举报
回复
[Quote=引用楼主 sinman 的帖子:]
rt
[/Quote]

用触发器?
BILearner 2009-05-15
  • 打赏
  • 举报
回复
Create table test
(id int,Score int)

Insert into test
select 100
union all select 0
union all select 0
union all select 100
union all select 80

Select Score,count(1) From test
group by Score
having count(1)>1 and sum(score)<>0
  • 打赏
  • 举报
回复
说明你的具体需求内容。
  • 打赏
  • 举报
回复
增加触发器,控制数据的插入和更新。
rmini 2009-05-15
  • 打赏
  • 举报
回复
在插入记录的时候就要判断该字段值,不过在修改记录的时候也要判断,这应该不是最好的方法。

期待更好的方法,继续关注!
lazyboysqaz 2009-05-15
  • 打赏
  • 举报
回复
不用触发器,额
无源码 额

这个貌似比较难啊

34,576

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧