How to delete all MS SQL Server Database Tables deployed in the webserver.??
Please NOTE:- I have only database credentials( DB name, username, password, host etc.) to connect the database and not a Cpanel etc.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Manikandan MurugesanRank #300 · 8.4K reputationPosted Jun 23, 2017, 4:38 PM EDT
I’ve recently been working on a data migration and I constantly been needing to delete all the tables in the db and start over. After doing some research I came across this hidden stored procedure in SQL Server that allows you to delete each table in the database you are connected to. Use this extremely carefully as you can’t rollback this and if you connect to the wrong db you’re going to wipe all the data.
try this
EXEC sp_MSforeachtable @command1 = “DROP TABLE ?”
You can also use the shell but I haven’t tried that
EXEC xp_cmdshell ‘SQLCMD -U -P -Q ‘EXEC sp_MSforeachtable @command1 = “DROP TABLE ?” ‘ ,no_output
Rajkiran SwainRank #165 · 14.4K reputationPosted Jun 24, 2017, 9:16 AM EDT