SQL SERVER 全テーブル削除
外部キーもあわせて
begin try while(exists(select 1 from information_schema.table_constraints where constraint_type='foreign key')) begin declare @sql nvarchar(2000) select top 1 @sql=('alter table ' + table_schema + '.[' + table_name + '] drop constraint [' + constraint_name + ']') from information_schema.table_constraints where constraint_type = 'foreign key' exec (@sql) end while(exists(select 1 from sysobjects where xtype='u')) begin select @sql=('drop table ' + name) from sysobjects where xtype = 'u' exec (@sql) end end try begin catch print error_message() end catch;