数据库中有两条记录的各列数值都一模一样,请问怎样删除一条?

pgz_007 2008-05-22 03:59:34
直接在企业管理器里面打开表的记录 发现无法删除。
请问有什么好办法吗?
...全文
603 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
Herb2 2008-05-23
  • 打赏
  • 举报
回复
declare @s varchar(8000)

alter table PricesMonthly add id int,checks bigint
set @s ='
declare @i int set @i = 1
update PricesMonthly set id = @i,@i= @i + 1,checks = checksum(*)
delete a from PricesMonthly a where exists(select 1 from PricesMonthly where id<a.id and checks=a.checks)
alter table PricesMonthly drop column id,checks'
exec(@s)
select * from PricesMonthly
pt1314917 2008-05-23
  • 打赏
  • 举报
回复


select distinct * into # from ta

truncate table ta

insert into ta select * from #
Herb2 2008-05-23
  • 打赏
  • 举报
回复
alter table ta add id int
declare @i int
set @i = 1
update ta set id = @i,@i= @i + 1
delete a from ta a where exists(select 1 from id<a.id and 字段比较)
alter table ta drop table id
cdzch 2008-05-23
  • 打赏
  • 举报
回复
select distinct * into # from ta

truncate table ta
insert into ta select * from ta
bing110 2008-05-22
  • 打赏
  • 举报
回复
呵呵,删除完全重复的记录。以上楼主的方法的确不错。之前遇到过要删除某些指定字段的记录,也在这里发一下。

declare @max integer,@id integer,@idcode
  declare cur_rows cursor local for select 主字段,count(*) from 表名 group by 主字段 having count(*) > 1
  open cur_rows
  fetch cur_rows into @id,@max
  while @@fetch_status=0
  begin
  select @max = @max -1
  set rowcount @max
  delete from 表名 where 主字段 = @id
  fetch cur_rows into @id,@max
  end
  close cur_rows
  set rowcount 0
dawugui 2008-05-22
  • 打赏
  • 举报
回复
select * , id = identity(int,1,1) into tmp from tb

delete from tmp t where id not in (select min(id) from tmp where 关键字 = t.关键字)
delete from tb
insert into tb select *(除了id字段) from tmp
drop table tmp
liangCK 2008-05-22
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 happyflystone 的回复:]
select distinct * into # from ta

truncate table ta
insert into ta select * from ta
[/Quote]
Limpire 2008-05-22
  • 打赏
  • 举报
回复
一模一样?

少量数据重复,先删除再insert

大量数据重复

select distinct * into # from tb
truncate table tb
insert tb select * from #
-狙击手- 2008-05-22
  • 打赏
  • 举报
回复
select distinct * into # from ta

truncate table ta
insert into ta select * from ta

34,838

社区成员

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

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