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

来源:互联网 发布:翻 墙软件 编辑:程序博客网 时间:2024/05/16 06:18

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

)

















0 0
原创粉丝点击