How to delete/drop all the tables from a SQL Server database
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
Love
Can we use Let's Encrypt, the free and open certificate authority?
Hola! gracias por la info, me sirvió el comando sacandole el nombre del server. En mi caso, fue una migración…
Yes 3rd option helped me too. I removed the WC key Values from config file then started working.
I know this is from 2014. But really, thank you!