请教一个存储过程的实现!

nettman 2008-12-31 08:35:10
一个数据库中有结构基本相同的数据表,希望将表A中与表B所有重复的字段删除掉,请教这个存储过程如何实现!
...全文
149 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
nettman 2008-12-31
  • 打赏
  • 举报
回复
感谢“wzy_love_sly ”的回复和“dawugui”给出的详细代码,先给分,再测试下,如果有问题再请教!
dawugui 2008-12-31
  • 打赏
  • 举报
回复
应该是删除数据. 

--前提:表中不能有text、ntext、image、cursor 数据类型的字段。

用CheckSum()最简单:

--查询
select * from A where checksum(*) not in (select checksum(*) from B)
select * from B where checksum(*) not in (select checksum(*) from A)

--删除
select * into c from A where checksum(*) not in (select checksum(*) from B)

delete * from A where checksum(*) not in (select checksum(*) from C)
delete * from B where checksum(*) not in (select checksum(*) from C)
drop table c




dawugui 2008-12-31
  • 打赏
  • 举报
回复
[Quote=引用楼主 nettman 的帖子:]
一个数据库中有结构基本相同的数据表,希望将表A中与表B所有重复的字段删除掉,请教这个存储过程如何实现!
[/Quote]
应该是删除数据.

--前提:表中不能有text、ntext、image、cursor 数据类型的字段。

用CheckSum()最简单:

--查询
select * from A where checksum(*) not in (select checksum(*) from B)
select * from B where checksum(*) not in (select checksum(*) from A)

--删除
delete * from A where checksum(*) not in (select checksum(*) from B)
nettman 2008-12-31
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 wzy_love_sly 的回复:]
是删除行吗?
[/Quote]

是的,是删除行!
wzy_love_sly 2008-12-31
  • 打赏
  • 举报
回复
是删除行吗?

22,207

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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