Sql Server快速删除多张表的所有约束的方法
declare @name varchar(500),@type varchar(10),@tbName varchar(500)DECLARE cur CURSOR STATICFORselect s.name,s.xtype,p.name tbName from sysobjects p inner join sysobjects s on s.parent_obj=p.idwhere p.n
declare @name varchar(500),@type varchar(10),@tbName varchar(500)
DECLARE cur CURSOR STATIC
FOR
select s.name,s.xtype,p.name tbName from sysobjects p inner join sysobjects s on s.parent_obj=p.id
where p.name like 'SC_T_%'
order by p.name
OPEN cur
WHILE 1=1
BEGIN
FETCH NEXT FROM cur INTO @name,@type,@tbName
if( @@fetch_status <> 0 ) break;
exec ('alter table '+@tbName+' drop constraint '+@name)
END
CLOSE cur
deallocate cur
更多推荐
所有评论(0)