判断数据库数据是否重复

zhangzhen_927116 2011-05-31 09:32:54
code tdate
KJ-1501-004-01 2008-10-04 00:00:00.000
KJ-1501-004-01 2008-10-05 00:00:00.000
KJ-1501-004-01 2009-08-08 00:00:00.000
判断KJ-1501-004-01的日期不重复,
比如我要修改
KJ-1501-004-01 2008-10-04 00:00:00.000
的时间
要查询表中KJ-1501-004-01的日期有没重复的
KJ-1501-004-01 2008-10-04 00:00:00:000
把他改成
KJ-1501-004-01 2008-10-05 00:00:00:000
或者
KJ-1501-004-01 2008-10-04 00:00:00:000
或者
KJ-1501-004-01 2008-10-08 00:00:00:000
都不行只能把
KJ-1501-004-01 2008-10-01 00:00:00.000



...全文
154 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
「已注销」 2011-05-31
  • 打赏
  • 举报
回复
查询:
select * from tb1 where code in (select code from tb1 group by code having (count(*) > 1))

更新:
update tb1 set tdate = [your date] where code = [your code]
and not exists(select 'x' from tb1 where code = [your code] and tdata = [your date])
yjytiantang 2011-05-31
  • 打赏
  • 举报
回复
update table set data=up_data
where id =KJ-1501-004-01 and NOT exists (select * from table where data=up_data);
zhangzhen_927116 2011-05-31
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 dropme 的回复:]
把日期分成日期和时间两个字段存,然后两个字段都设置成不允许重复的可以么?
[/Quote]
不能修改数据库里面的表,只能是在程序中判断。
dropme 2011-05-31
  • 打赏
  • 举报
回复
把日期分成日期和时间两个字段存,然后两个字段都设置成不允许重复的可以么?

2,496

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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