当先锋百科网

首页 1 2 3 4 5 6 7

清空外键


declare @sql varchar(max),
 @tab_name varchar(128),
 @fk_name varchar(128);
declare c cursor for
select OBJECT_NAME(parent_object_id), name from sys.objects where type='F'


open c
fetch next from c into @tab_name, @fk_name 
while @@FETCH_STATUS=0
begin 
 set @sql='';
 set @sql='alter table ' + @tab_name + ' drop constraint ' + @fk_name
 print @sql
 exec(@sql)
 
 fetch next from c into @tab_name, @fk_name
end
close c
deallocate c


select OBJECT_NAME(parent_object_id) 'table', * from sys.objects where type='F'


删除所有表

exec sp_msforeachtable "drop table ? "