【问题标题】:How to delete taggregate_temp_ tables at once?如何一次删除 taggregate_temp_ 表?
【发布时间】:2014-07-23 04:10:23
【问题描述】:

在我的 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_ 开头的表
你能帮帮我吗?

【问题讨论】:

    标签: mysql sql phpmyadmin


    【解决方案1】:

    另一个用户回答了这个问题: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?

    【讨论】:

    • 我需要替换 DATABASE_NAME 吗?
    • 是的,您需要定义要针对哪个数据库运行命令。
    • 我需要替换 Table_Name 吗?
    • 不,Table_Name 是信息架构中列的名称。在编辑中我提到这个 sql 是特定于 SQL Server 的,但是有一个指向 MySQL 特定示例的链接
    猜你喜欢
    • 2022-11-28
    • 2019-10-30
    • 2022-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-09
    • 2013-07-24
    • 1970-01-01
    相关资源
    最近更新 更多