rgb192
asked on
list many tables so I can delete them
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
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
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.
https://www.experts-exchange.com/questions/27289072/drop-multiple-tables-with-one-command.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?
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?
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.
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.
ASKER
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
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
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?
DROP TABLE table1, table2, table3, ...
and then execute it. Is that correct?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
>>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
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
Did you see Lowfatspread's solution?
ASKER
>>
select 'Drop table ['+table_schema+'].['+tabl e_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
select 'Drop table ['+table_schema+'].['+tabl
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
>>select 'Drop table ['+table_schema+'].['+tabl e_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
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
ASKER
select 'Drop table ['+table_schema+'].['+tabl e_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
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
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks