如何一次删除taggregate_temp_表?

时间:2014-06-02 23:12:55

标签: mysql sql phpmyadmin

在我的SQL中,我有多个表,如:


taggregate_temp_1364792160
taggregate_temp_1364795760
taggregate_temp_1364799360
taggregate_temp_1364802960
taggregate_temp_1364806560
taggregate_temp_1364810160
taggregate_temp_1364813760
taggregate_temp_1364817360
taggregate_temp_1364820960
taggregate_temp_1364824560
taggregate_temp_1364828160
taggregate_temp_1364831760
taggregate_temp_1364835360
taggregate_temp_1364838960
taggregate_temp_1364842560
taggregate_temp_1364846160
taggregate_temp_1364849760
taggregate_temp_1364853360

我需要一次删除以:taggregate_temp_开头的所有表
你能帮帮我吗?

1 个答案:

答案 0 :(得分:0)

另一位用户回答了这个问题:Drop all tables whose names begin with a certain string

您需要执行类似

的操作
USE DATABASE_NAME
GO

declare @cmd varchar(4000)
declare cmds cursor for 

select 'DROP TABLE [' + Table_Name + ']'
from INFORMATION_SCHEMA.TABLES
where Table_Name like 'taggregate_temp_%'

open cmds
while 1=1
begin
    fetch cmds into @cmd
    if @@fetch_status != 0 break
    exec(@cmd)
end
close cmds;
deallocate cmds

编辑:你没有在问题中提到mysql,但是我刚刚看到了标签,看一下mysql示例的以下主题:MySQL bulk drop table where table like?