求一sql语句....

yuranccc2003 2005-08-24 01:23:52
数据库中有完全相同的两条记录,怎样删除一条留下一条?
如果不行,就都删除吧。
...全文
55 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
hsj20041004 2005-08-24
  • 打赏
  • 举报
回复
如果有id

delete from tablename a where exists(select * from tablename where a.id<id and a.col1=col1)


如果没有id
alter table tablename add id int identity(1,1)
delete from tablename a where exists(select * from tablename where a.id<id and a.col1=col1)
alter table tablename drop column id


-----
select distinct * into #t from 原表
truncate table 原表
insert into 原表 select * from #t
drop table #t
凨叔 2005-08-24
  • 打赏
  • 举报
回复
select distinct * into #temp from table1
delete from table1
insert into table1 select * from #temp
drop table #temp
凨叔 2005-08-24
  • 打赏
  • 举报
回复
可以
select * into #temp from table1
delete from table1
insert into table1 select * from #temp
rivery 2005-08-24
  • 打赏
  • 举报
回复
select distinct col1,col2 into #t from tablename
delete from tablename
insert into tablename from #t
drop table #t

34,590

社区成员

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

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