In my earlier post, SQL SERVER – How to DELETE Multiple Table Together Via SQL Server Management Studio (SSMS)? I showed you how to DROP Statement multiple tables together using a wizard in SQL Server Management Studio (SSMS).
Lots of developers are not aware that they can do it using single DROP statement.
Let us create the following three tables to demonstrate dropping multiple tables using a single DROP statement
USE TempDB GO CREATE TABLE testing1(ID INT, NAME VARCHAR(100)); CREATE TABLE testing2(ID INT, NAME VARCHAR(100)); CREATE TABLE testing3(ID INT, NAME VARCHAR(100));
Now to DROP all of these three tables, you do not need to use three DROP statements, All you need to do is simply use single DROP statement and specify the three table names separated by comma as shown below
DROP TABLE testing1,testing2,testing3;
That’s it. All three tables testing1,testing2, and testing3 are dropped
How many of you know this tip?
In your code, if you create lots of temporary tables and want to drop all of them at the end, you can make use of this simple tip.
If you have such a script, I request you to share the same with me. I will be happy to post the script with due credit to you over here.
Here are a few interesting blog posts:
Reference: Pinal Dave (https://blog.SQLAuthority.com)