龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 数据库类 > Sql Server开发 >

删除没有主键的表中的重复记录

时间:2013-01-03 18:08来源:未知 作者:admin 点击:
分享到:
删除没有主键的表中的重复记录 create procedure delrepeat as begin SELECT distinct * INTO testTemp FROM test delete from test insert into test SELECT * FROM testTemp drop table testTemp end distinct:用于查询中去除重复项

删除没有主键的表中的重复记录

create procedure delrepeat

as
begin
SELECT distinct *  INTO testTemp FROM test
delete from test
insert into test SELECT *  FROM testTemp
drop table testTemp
end

distinct:用于查询中去除重复项

begin~end范围语句表示存储过程中作为整体执行的语句块

oracle数据库教程

delete from a1 where rowid not in(select max(rowid) from a1 group by aa,bb,cc);    --以物理行号rowid来处理,很是活学活用:)
ern的贴子


用临时表的方法
 
CREATE TABLE TMP_TABLE SELECT DISTINCT * FROM TABLE_NAME;
DROP TABLE_NAME;
CREATE TABLE TABLE_NAME SELECT * FROM TMP_TABLE;
DROP TMP_TABLE;
COMMIT;


精彩图集

赞助商链接