您的位置:首页 > 数据库

SQLserver 查看表详细信息--删除重复数据

2015-04-23 21:38 337 查看
sp_help table_name  --查询表详细信息sql server

desc tables table_name

删除重复数据:

1、oracle 中

delete borrowRecord 
--删除表名

where studentId in( --删除重复数据

select studentId from borrowRecord group by studentId having count(studentId)>1

)

and rowid not in( --保留重复数据中的一条数据

select min(rowid) from borrowRecord group by studentId having count(studentId)>1 

)

2、SQL server中

delete BorrowRecord   
--BorrowRecord 表名

where studentId in(
select studentId from borrowRecord group by studentId having count(studentId)>1
--找出重复的数据

)

and borrowid not in(
select min(borrowId) from borrowRecord group by studentId having count(studentId)>1
--保留重复数据中的一条数据

)

3、删除所有重复的数据

delete from table_name

where id in(

select id from table_name group by id having count(id)>1

)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: