I don't want to type all tables' name to drop all of them. Is it possible with one query?
相关问题
- SQL join to get the cartesian product of 2 columns
- sql execution latency when assign to a variable
- Difference between Types.INTEGER and Types.NULL in
- What is the best way to cache a table from a (SQL)
- php PDO::FETCH_ASSOC doesnt detect select after ba
I'd just make a small change to @NoDisplayName's answer and use
QUOTENAME()
on theTABLE_NAME
column and also include theTABLE_SCHEMA
column encase the tables aren't in thedbo
schema.Or using
sys
schema views (as per @swasheck's comment):As a follow-up to Dave.Gugg's answer, this would be the code someone would need to get all the DROP TABLE lines in MySQL:
If anybody else had a problem with best answer's solution (including disabling foreign keys), here is another solution from me:
Use the INFORMATION_SCHEMA.TABLES view to get the list of tables. Generate Drop scripts in the select statement and drop it using Dynamic SQL:
Sys.Tables Version
Note: If you have any
foreign Keys
defined between tables then first run the below query to disable allforeign keys
present in your database.For more information, check here.
If you don't want to type, you can create the statements with this:
Then copy and paste into a new SSMS window to run it.
I Know this question is very old but every Time i need this code .. by the way if you have tables and views and Functions and PROCEDURES you can delete it all by this Script .. so why i post this Script ?? because if u delete all tables you will need to delete all views and if you have Functions and PROCEDURES you need to delete it too
i Hope it will help someone