5种情况下sql server删除数据的方法

数据库 SQL Server
根据不同的情况,删除SQL数据库中的方法也有所不同,下文介绍了5种情况下sql server删除数据的方法,希望对您能有所启迪。

有很多种方法都可以实现sql server删除数据,下面就为您介绍了其中5种最常见的方法,如果您对sql server删除数据方面感兴趣的话,不妨一看。

1、查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断
select * from people
where peopleId in (select peopleId from people group by peopleId having count(peopleId) > 1)

2、删除表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断,只留有rowid最小的记录
delete from people
where peopleId in (select peopleId from people group by peopleId   having count(peopleId) > 1)
and rowid not in (select min(rowid) from people group by peopleId having count(peopleId )>1)

3、查找表中多余的重复记录(多个字段)
select * from vitae a
where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)

4、sql server删除数据--删除表中多余的重复记录(多个字段),只留有rowid最小的记录
delete from vitae a
where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)
and rowid not in (select min(rowid) from vitae group by peopleId,seq having count(*)>1)

5、查找表中多余的重复记录(多个字段),不包含rowid最小的记录
select * from vitae a
where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)
and rowid not in (select min(rowid) from vitae group by peopleId,seq having count(*)>1)
 

 

 

【编辑推荐】

sql server删除有默认值的列的方法

SQL SERVER连接失败的解决方案

带您了解SQL Server游标

八步轻松搞定SQL Server自动备份

SQL Server的优点和缺点

责任编辑:段燃 来源: 互联网
相关推荐

2010-10-22 17:26:55

SQL Server删

2010-04-25 17:34:30

负载均衡实现

2010-11-10 11:42:35

SQL Server2

2010-09-02 10:15:46

SQL删除

2010-06-30 10:55:13

SQL Server日

2010-07-13 16:07:26

SQL Server行

2010-06-28 15:27:54

SQL Server

2010-10-22 16:29:11

SQL Server删

2015-06-29 14:11:30

网络接入无线网络

2010-07-09 09:34:37

SQL Server数

2010-09-01 16:55:55

SQL删除连接

2010-11-10 13:28:06

SQL Server删

2011-09-13 15:51:54

删除数据库重复行

2010-07-30 15:32:23

2010-09-28 15:46:22

SQL删除重复记录

2018-01-08 19:17:21

数据库Oracle重启

2010-11-10 11:54:32

SQL SERVER删

2010-10-20 10:19:33

sql server删

2010-11-03 13:09:14

DB2卸载方法

2010-09-03 11:00:47

SQL删除
点赞
收藏

51CTO技术栈公众号