当前位置:首页 » 编程语言 » sql批量删除相似名称
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

sql批量删除相似名称

发布时间: 2022-06-03 02:07:25

‘壹’ mysql 怎么通过sql语句如何批量去掉某一个表中某一个字段的下面的相同部分字符串。

建议你用正则匹配

‘贰’ SQL语句求助:批量删除具有相同前缀的表

在phpmyadmin中先运行(假设前缀是"cdb_"):
select concat('drop table ', table_name, ';')
from information_schema.tables;
where table_name like 'cdb_%'

然后把执行的结果从网页中复制出来,粘贴到记事本中,把记事本中的文件另存为:droptable.sql 。(文件类型中选“所有文件”)

在phpmyadmin中,顶部的菜单中,有“import”,点击后,你把新建的文件上传上去,然后点击右下方的“执行”

‘叁’ sql如何删除重复数据

sql查询去除重复值语句
sql 单表/多表查询去除重复记录
单表distinct
多表group by
group by 必须放在 order by 和 limit之前,不然会报错
************************************************************************************
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、删除表中多余的重复记录(多个字段),只留有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(*)>

‘肆’ sql server 中如何删除相同名字的信息

直接给你代码啦,--取重名
select * from table as t1 where exists(select 1 from table as t2 where t1.name = t2.name and t1.age <> t2.age)

--删重名
delete from table as t1 where exists(select 1 from table as t2 where t1.name = t2.name and t1.age <> t2.age)

‘伍’ 怎么使用SQL语句批量删除多个表的相同字段

在phpmyadmin中先运行(假设前缀是\"cdb_\"):
select
concat(\'drop
table
\',
table_name,
\';\')
from
information_schema.tables;
where
table_name
like
\'cdb_%\'
然后把执行的结果从网页中复制出来,粘贴到记事本中,把记事本中的文件另存为:droptable.sql
。(文件类型中选“所有文件”)
在phpmyadmin中,顶部的菜单中,有“import”,点击后,你把新建的文件上传上去,然后点击右下方的“执行”

‘陆’ 如何在Sql中将重复的所有字段删除

用SQL语句,删除掉重复项只保留一条
在几千条记录里,存在着些相同的记录,如何能用SQL语句,删除掉重复的呢
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
peopleName
in
(select
peopleName
from
people
group
by
peopleName
having
count(peopleName)
>
1)
and
peopleId
not
in
(select
min(peopleId)
from
people
group
by
peopleName
having
count(peopleName)>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、删除表中多余的重复记录(多个字段),只留有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)
6.消除一个字段的左边的第一位:
update
tableName
set
[Title]=Right([Title],(len([Title])-1))
where
Title
like
'村%'
7.消除一个字段的右边的第一位:
update
tableName
set
[Title]=left([Title],(len([Title])-1))
where
Title
like
'%村'
8.假删除表中多余的重复记录(多个字段),不包含rowid最小的记录
update
vitae
set
ispass=-1
where
peopleId
in
(select
peopleId
from
vitae
group
by
peopleId

‘柒’ 用SQL如何批量删除具有相同前缀的表sql批量删除表

alter proc DeleteSingleTable(@tablename varchar(100))
as
begin
declare @SQL varchar(2000)
declare @constraintName varchar(100)

declare curName cursor for
select name from sysobjects
where xtype = 'f ' and parent_obj =
(select [id] from sysobjects where [name]=@tablename and xtype = 'u ')

open curName
fetch next from curName into @constraintName
while @@fetch_status = 0
begin
set @SQL = 'alter table ' + @tablename + ' drop constraint '
set @SQL = @SQL + @constraintName
exec(@SQL)
fetch next from curName into @constraintName
end
close curName
deallocate curName
end