• sql server 删除所有表、视图、存储过程


    本文来自:http://www.cnblogs.com/yjss/articles/2065664.html

    1.删除表

    use 数据库名
    declare mycur cursor local for select [name] from dbo.sysobjects where xtype='U'
    declare @name varchar(100)
     
    OPEN mycur
     
    FETCH NEXT from mycur into @name
     
    WHILE @@FETCH_STATUS = 0 
     
    BEGIN
    exec('drop table ' + @name)
    FETCH NEXT from mycur into @name
    END
     
    CLOSE mycur
    

     2.删除视图

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

      3.删除存储过程

    use 数据库名
    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
    

     4.查看被锁表

    select   request_session_id   spid,OBJECT_NAME(resource_associated_entity_id) tableName   
    from   sys.dm_tran_locks where resource_type='OBJECT'
    

    5.清除锁死的表

    Exec dbo.sp_lock  
    begin  
    declare @i int--定义要清除的线程id  
    declare @SQL nvarchar(3000);  
    set @i =0;  
    while(@i<10000)  
    begin  
    --清除所有的占用线程  
    set @SQL=N'kill '+convert(varchar(20),@i)  
    exec sp_executesql  @SQL;  
    set @i=@i+1;  
    end  
    end 
    

      

  • 相关阅读:
    android ListView 获取点击的选项
    架构流程笔记
    关键字搜索
    利用HttpWebRequest模拟提交图片
    (一)phonegap自学---不会java也会写原生app
    js正则笔记
    jQuery插件编写,
    存储过程分页
    JavaScript中的this陷阱
    jQuery.Deferred(jQuery1.5-2.1)源码剖析
  • 原文地址:https://www.cnblogs.com/jt789/p/5558236.html
Copyright © 2020-2023  润新知