up vote 2 down vote favorite
share [g+] share [fb]

Is there an easy way to delete multiple tables in the database without dropping the database and recreating it? In this case we have over 100 to remove.

I am happy enough to remove all user tables and reimport the needed data but can't touch any of the database security settings.

link|improve this question

67% accept rate
feedback

3 Answers

up vote 5 down vote accepted

In object explorer, navigate to the database you're interested in. Expand it out and click on the Tables folder. Hit F7 to bring up the Object Explorer Details. Select the tables you want to delete and press the delete key.

link|improve this answer
feedback

Any reason not to do it directly in T-SQL (with DROP TABLE)? Then it's just a case of creating the appropriate SQL script (quite possibly autogenerating it if you've got a list of the tables you need to delete) and you're away.

link|improve this answer
feedback

Tsql answer as suggested. I couldn't get the drop table to work in tsql but this did the trick.

declare @TABLE varchar(250)

declare select_cursor cursor for
select name from sysobjects where type='U'

open select_cursor

fetch next from select_cursor
into @TABLE

while @@FETCH_STATUS = 0
begin
    print 'DROP TABLE '+@TABLE

    fetch next from select_cursor
    into @TABLE
end

close select_cursor
deallocate select_cursor
link|improve this answer
This assumes no foreigh key constraints are in place. – K. Brian Kelley May 12 '09 at 13:33
You can crawl dependencies and drop the tables in order with a bit more effort. The stackoverflow posting at <a href=stackoverflow.com/questions/352176/…; has some solutions for doing this. – ConcernedOfTunbridgeWells May 12 '09 at 17:03
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.