SQLSERVER는 모든 테이블, 저장 프로세스 및 보기를 삭제합니다.

4658 단어
--      
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 next from c1 into @c1
while(@@fetch_status=0)
begin
exec(@c1)
fetch next from 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)

--    :

declare v_mycur cursor local for select [name] from dbo.sysobjects where xtype='V'  --    
declare @vname varchar(100) 
  
OPEN v_mycur    --    
  
FETCH NEXT from v_mycur into @vname
  
WHILE @@FETCH_STATUS = 0  
  
BEGIN 
exec('drop VIEW ' + @vname) 
FETCH NEXT from v_mycur into @vname   --    
END 
  
CLOSE v_mycur   --    

 

--      :



declare mycur cursor local for select [name] from dbo.sysobjects where xtype='P'
declare @name varchar(100) 
  
OPEN mycur 
  
FETCH NEXT from mycur into @name
  
WHILE @@FETCH_STATUS = 0  
  
BEGIN 
exec('drop PROCEDURE ' + @name) 
FETCH NEXT from mycur into @name
END 
  
CLOSE mycur

좋은 웹페이지 즐겨찾기