Introduction
When as a developer working in a database, which is in Development state, we may create some physical tables or temp tables to check the logic. Or based on the initial requirement we may have created more tables as part of Normalizing the data and our reviewer may suggest some better ideas to accommodate those data in already existing table.
Later some point, once the data is defined we may create a proper table and delete the temporarily created table. If we created only one table then its not too big to drop it. But what if we have created some more tables and those are required to drop?. We may end up in writing multiple drop statements for each tables. But we can achieve multiple tables dropping in one single Drop Statement
Dropping Tables
The normal way we all follow to drop more tables is,
DROP TABLE DemoIndex
DROP TABLE DemoIndexFirstName
DROP TABLE DemoNonIndex
Hereafter reading this article, this method is not required to follow. Try to follow the below T-SQL Statement,
DROP TABLE DemoIndex ,DemoIndexFirstName ,DemoNonIndex
If we are not sure if the table exists or not, we can also check that with IF EXISTS keywords
DROP TABLE IF EXISTS DemoIndex ,DemoIndexFirstName ,DemoNonIndex
GitHub – A sample T-SQL Statements for this is uploaded here
Conclusion
In this simple article, I have share a useful tips to drop more tables in a single statement. I hope you all found this article useful. Please share your feedback in the comment section. We will discuss more tips and tricks in T-SQL statements in our upcoming articles.
Leave a Reply