How to drop all tables from a database with one SQL query?

后端 未结 12 2079
盖世英雄少女心
盖世英雄少女心 2020-12-12 09:44

I don\'t want to type all tables\' name to drop all of them. Is it possible with one query?

12条回答
  •  伪装坚强ぢ
    2020-12-12 10:07

    For me I just do

    
    DECLARE @cnt INT = 0;
    
    WHILE @cnt < 10 --Change this if all tables are not dropped with one run
    BEGIN
    SET @cnt = @cnt + 1;
    EXEC sp_MSforeachtable @command1 = "DROP TABLE ?"
    END
    
    

提交回复
热议问题