Search code examples
sql-serverentity-frameworkazure-sql-database

How can I delete all tables in an Azure SQL Database?


When I've changed my schema in ways that EF migrate doesn't work (it tries, it really really tries), I want to delete all the tables from my databases. Is there a way to do so other than a SQL script that first deletes the content of all the tables, then drops all the tables, in the order required by the PK:FK relationships?

None of the answers here worked.


Solution

  • Is there a way to do so other than a SQL script that first deletes the content of all the tables, then drops all the tables, in the order required by the PK:FK relationships?

    There's no need to delete the rows. That's an expensive operation. Just drop the tables.

    And you can either script a DROP for all the foreign keys, or just run the table drop script over and over until all the tables are gone (assuming you have no circular FK dependencies).

    But it will be easier to just rename the old database and create a new one.