Alternatives · Basic Logics · Real Scenario Logic's

To Drop Multiple Tables in a Single Query in SQL Server

Introduction

In this Blog post, we will see how to Drop Multiple Tables in a Single Query in SQL Server. The below Script would work in both Azure SQL DB and On-Premises.

Demo SQL Script

--Creating Table 
CREATE TABLE TEST_1 ( ID INT NOT NULL, NAMES VARCHAR(30) NOT NULL);
GO
 
--Populating the Data in Table
INSERT INTO TEST_1 (ID,NAMES) VALUES (1,'A'),(2,'B');

--Creating Table 
CREATE TABLE TEST_2 ( ID INT NOT NULL, NAMES VARCHAR(30) NOT NULL);
GO
 
--Populating the Data in Table
INSERT INTO TEST_2 (ID,NAMES) VALUES (1,'A'),(2,'B');
 
--Viewing the Records
SELECT 'TEST_1' AS Table_Name,* FROM TEST_1;
GO
SELECT 'TEST_2' AS Table_Name,* FROM TEST_2;
GO

To Drop Tables one by one

SQL SCRIPT

DROP TABLE TEST_1;
GO
DROP TABLE TEST_2;
GO

To Drop Multiple Tables in a Single Query

SQL SCRIPT

DROP TABLE TEST_1,TEST_2;

Conclusion

Thus, we saw how to drop multiple tables in a single query easily in SQL Server. The Above example is unit tested in both Azure SQL db and On-Premises.

Thanks for reading!

FOLLOW BLOG for Interesting Upcoming Posts!

Advertisement

4 thoughts on “To Drop Multiple Tables in a Single Query in SQL Server

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s