sql删库到跑路
--/第1步**********删除所有表的外键约束*************************/
DECLARE c1 cursor forselect 'alter table ['+ object_name(parent_obj) + '] drop constraint ['+name+']; 'from sysobjectswhere xtype = 'F'open c1declare @c1 varchar(8000)fetch next from c1 into @c1while(@@fetch_status=0)beginexec(@c1)fetch next from c1 into @c1endclose c1deallocate c1 --/第2步**********删除所有表*************************/ use 数据库名(是要删除表的所在的那个数据库的名称)GOdeclare @sql varchar(8000)while (select count(*) from sysobjects where type='U')>0beginSELECT @sql='drop table ' + nameFROM sysobjectsWHERE (type = 'U')ORDER BY 'drop table ' + nameexec(@sql)end

浙公网安备 33010602011771号