Search code examples
sql-serversql-server-2008adhocsyssql-server-2008r2-express

How to delete all tables from db? Cannot delete from sys.tables


How can I perform this query on whatever way:

delete from sys.tables where is_ms_shipped = 0

What happened is, I executed a very large query and I forgot to put USE directive on top of it, now I got a zillion tables on my master db, and don't want to delete them one by one.

UPDATE: It's a brand new database, so I don't have to care about any previous data, the final result I want to achieve is to reset the master db to factory shipping.


Solution

  • Simplest and shortest way I did was this:

    How to Rebuild System Databases in SQL Server 2008

    The problem with all other answers here is that it doesn't work, since there are related tables and it refuses to execute.

    This one, not only it works but actually is what I am looking for: "Reset to factory defaults" as stated in the question.
    Also this one will delete everything, not only tables.