2

How to delete selected 100's of database in an easy way? I'm using SQL Server.

Example:

dbo.temp1
dbo.temp2
dbo.temp3
.
.
.
dbo.temp98
dbo.temp99
dbo.temp100
dbo.temp101
dbo.temp102

I just want to delete dbo.temp1 to dbo.temp100.

1
  • You could use the undocumented sp_MSForEachTable stored procedure to run a script for every table. This script would check the name and drop it. You can probably find an example of this somewhere. weblogs.sqlteam.com/joew/archive/2007/10/23/60383.aspx Commented Apr 30, 2015 at 3:06

1 Answer 1

2

First run this to check it lists only the tables you want to drop:

EXEC sp_MSForEachTable 'IF LEFT(''?'',11) = ''[dbo].[temp''  PRINT ''?'''

If it does, run this:

EXEC sp_MSForEachTable 'IF LEFT(''?'',11) = ''[dbo].[temp''  DROP TABLE ?'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.