DECLARE @tablename VARCHAR(30),@sql VARCHAR(500)DECLARE cur_delete_table CURSOR READ_ONLY FORWARD_ONLY FORSELECT name FROM sysobjects WHERE name LIKE 'PUB%' AND type='U'OPEN cur_delete_tableFETCH NEXT FROM cur_delete_table INTO @tablenameWHILE @@FETC
以下通过触发器批量删除数据库中的表,SQL2008已验证 DECLARE @Table NVARCHAR() DECLARE @Count Int = DECLARE tmpCur CURSOR FOR SELECT name FROM sys.objects WHERE TYPE='U' AND name LIKE N'temp_cost%' order by name OPEN tmpCur FETCH NEXT FROM tmpCur INTO @Table WHILE @@FETCH_S
delete from zqzrdp where tel in (select min(dpxx_id) from zqzrdp group by tel having count(tel)>1); 运行,报错 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMTU5ODUyOQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast"
SELECT concat('DROP TABLE IF EXISTS ', table_name, ';') FROM information_schema.tables WHERE table_schema = 'mydb'; mydb换成你想删除的数据库的名字这样可以生成一个批量处理的sql语句,你需要再运行一次这个结果集就可以删除所有的表而不删除数据库了
1. 查询需要删除的记录,会保留一条记录. select a.id,a.subject,a.RECEIVER from test1 a left join (select c.subject,c.RECEIVER ,max(c.id) as bid from test1 c where status=0 GROUP BY RECEIVER,SUBJECT having count(1) >1) b on a.id< b.bid where a.subject=b.subject and a.R
要删除所有的用户表: declare @sql varchar(8000) SELECT @sql='drop table ' + name FROM sysobjects WHERE (type = 'U') ORDER BY 'drop table ' + name exec(@sql) 如果要删除所有用户表中的内容,可以执行以下语句: declare @sql varchar(8000) SELECT @sql='truncate table ' + name FROM sysobject
数据库中表没有添加主键,误插入了两条数据,现在需要删除其中一条记录. 利用rowid号,因为表中的每一行数据都有一个rowid,这个rowid 号是不同的,用select可以查询出来. select rowid from table1; delete from table1 where rowid='xxxx';
select concat('drop table ',table_name,';') from TABLES where table_schema='数据库名称'; select concat('truncate ',table_name,';') from TABLES where table_schema='数据库名称';
create or replace function count_rows/**查询各表实际记录数*/(table_name in varchar2,owner in varchar2 default null)return numberauthid current_userIS num_rows number; stmt varchar2(2000);begin if owner is null then stmt := 'select count(*) from "'||table_name