?
Solved

list many tables so I can delete them

Posted on 2011-09-03
13
Medium Priority
?
346 Views
Last Modified: 2012-05-12
select * tables from database


I want to drop alot of tables so
I want the output to look like this

drop tables table1,table2,table3,...


or a way I can easy copy paste
0
Comment
Question by:rgb192
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 2
  • +2
13 Comments
 
LVL 5

Expert Comment

by:Brian Chan
ID: 36478240
I don't think you can drop multiple tables in a single DROP statement. I ususlly use excel spreadsheet to concatenate the table name with the "DROP TABLE", or with my favourite text editor, Notepad++, which has the feature to insert like column.
0
 
LVL 14

Expert Comment

by:leoahmad
ID: 36478248
http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SQL-Server-2005/Q_27289072.html

As you have already been suggested that you cannot do that in single statement, why not use the script given in the above link and get statements of deletion.

By the way, why you want a single statement?
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 36478273
Why are you reposting the same question?

Here is my answer from your last duplicate question:
You should be able to do:
DROP TABLE table1, table2, table3

>>is there a right click shortcut<<
From Object Explorer Details in SSMS you can select them all and then delete them all at once.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:rgb192
ID: 36478316
I need a select * tables from database

or I would have to write 50 databases by hand



eventually I want to delete them


but most important, I need to know the tablenames
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 36478340
So instead of  just deleting them all from SSMS with one delete, you want a SQL statement to concatenate all your table names and build your DROP TABLE to look like this:
DROP TABLE table1, table2, table3, ...
and then execute it.  Is that correct?

0
 
LVL 50

Accepted Solution

by:
Lowfatspread earned 1000 total points
ID: 36478354
select 'Drop table ['+table_schema+'].['+table_name+']'
from information_schema.tables
where table_type='Base Table' -- to ignore views
 and table_name like ',,,,%'
order by 1

you may also wish to investigate the procedure sp_msforeachtable

which allows you to construct sql commands to process against a set of tables...
0
 

Author Comment

by:rgb192
ID: 36479031
>>So instead of  just deleting them all from SSMS with one delete, you want a SQL statement to concatenate all your table names and build your DROP TABLE to look like this:
DROP TABLE table1, table2, table3, ...
and then execute it.  Is that correct?


correct



but first is there a way I can select the names of my tables so I dont have to write by hand
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 36479325
Did you see Lowfatspread's solution?
0
 

Author Comment

by:rgb192
ID: 36519235
>>
select 'Drop table ['+table_schema+'].['+table_name+']'
from information_schema.tables
where table_type='Base Table' -- to ignore views
 and table_name like ',,,,%'
order by 1

is there a sample command so I dont destroy all my tables







>>
you may also wish to investigate the procedure sp_msforeachtable

I do not understand

>>
which allows you to construct sql commands to process against a set of tables...

I do not understand
0
 
LVL 50

Expert Comment

by:Lowfatspread
ID: 36519285
>>select 'Drop table ['+table_schema+'].['+table_name+']'
from information_schema.tables
where table_type='Base Table' -- to ignore views
 and table_name like ',,,,%'
order by 1


just generates the command ... it doesnt actually run the drop...


 >>procedure sp_msforeachtable
http://www.databasejournal.com/features/mssql/article.php/3441031/SQL-Server-Undocumented-Stored-Procedures-spMSforeachtable-and-spMSforeachdb.htm

0
 

Author Comment

by:rgb192
ID: 36555100
select 'Drop table ['+table_schema+'].['+table_name+']'
from information_schema.tables
where table_type='Base Table' -- to ignore views
 and table_name like ',,,,%'
order by 1



returns a column named (No column name)
and no results
0
 
LVL 75

Assisted Solution

by:Anthony Perkins
Anthony Perkins earned 1000 total points
ID: 36555270
You are obviously not grasping the intent so let's try it this way (No points please as this is Lowfatspread's solution):
SELECT  'Drop table [' + table_schema + '].[' + table_name + ']'
FROM    information_schema.tables
0
 

Author Closing Comment

by:rgb192
ID: 36556834
thanks
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article will provide a solution for an error that might occur installing a new SQL 2005 64-bit cluster. This article will assume that you are fully prepared to complete the installation and describes the error as it occurred durin…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question