SQL:删除表中一再的记录
发布时间:2020-12-31 11:32:54 所属栏目:编程 来源:网络整理
导读:本日PHP站长网 52php.cn把网络自互联网的代码分享给各人,仅供参考。 --建设测试表if object_id('test') is not null drop table testcreate table test( id int identity(1,1) primary key,name varchar(50))--插入几条
以下代码由PHP站长网 52php.cn网络自互联网 此刻PHP站长网小编把它分享给各人,仅供参考 --建设测试表 if object_id('test') is not null drop table test create table test ( id int identity(1,1) primary key,name varchar(50) ) --插入几条测试数据 insert into test select 'a' union all select 'a' union all select 'a' union all select 'a' union all select 'a' union all select 'a' union all select 'b' union all select 'b' union all select 'b' union all select 'b' union all select 'b' union all select 'b' union all select 'b' union all select 'c' union all select 'c' union all select 'c' union all select 'd' union all select 'd' --查察当前记录 select * from test if object_id('#') is not null drop table # --留意(是单个字段的差异照旧多个字段,这里是name) select distinct (name) into # from test --查察新表中的数据 select * from # --清空旧表 truncate table test --将新表中的数据插入到旧表 insert test select * from # --删除新表 drop table # --查察功效 select * from test 查找表中多余的一再记录,一再记录是按照单个字段(peopleId)来判定? 以上内容由PHP站长网【52php.cn】网络清算供各人参考研究 假如以上内容对您有辅佐,接待保藏、点赞、保举、分享。 (编辑:湖南网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |