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
If you want to use only one SQL query to delete all tables you can use this:
This is a hidden Stored Procedure in sql server, and will be executed for each table in the database you're connected.
Note: You may need to execute the query a few times to delete all tables due to dependencies.
Note2: To avoid the first note, before running the query, first check if there foreign keys relations to any table. If there are then just disable foreign key constraint by running the query bellow:
Not quite 1 query, still quite short and sweet:
You could also use the following script to drop everything, including the following:
https://michaelreichenbach.de/how-to-drop-everything-in-a-mssql-database/
The simplest way is to drop the whole database and create it once again:
That's all.
Use the following script to
drop
allconstraints
:Then run the following to drop all tables:
This worked for me in Azure SQL Database where
'sp_msforeachtable'
was not available!