0

In my SQL I have multi tables like:


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

I need to delete all tables begin with: taggregate_temp_ at once
Can you help me please?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
tahafahed
  • 383
  • 1
  • 3
  • 7

1 Answers1

0

This question was answered by another user: Drop all tables whose names begin with a certain string

You will want to do something like

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

Edit: You didn't mention mysql in the question, but I just saw the tag, have a look at the following topic for a mysql example: MySQL bulk drop table where table like?

Community
  • 1
  • 1
Tsarin
  • 171
  • 4