方便刪除數據庫中所有的數據表,清空數據庫,有些有約束,不能直接delete,需要先刪除庫中的約束,代碼如下
復制代碼 代碼如下:
--刪除所有約束
DECLARE c1 cursor for
select'alter table ['+ object_name(parent_obj)+'] drop constraint ['+name+']; '
from sysobjects
where xtype ='F'
open c1
declare @c1 varchar(8000)
fetch nextfrom c1 into@c1
while(@@fetch_status=0)
begin
exec(@c1)
fetch nextfrom c1 into@c1
end
close c1
deallocate c1
--刪除數據庫所有表
declare @tname varchar(8000)
set@tname=''
select@tname=@tname+Name+','from sysobjects where xtype='U'
select@tname='drop table '+ left(@tname,len(@tname)-1)
exec(@tname)
新聞熱點
疑難解答