sqlserver批量删除表

--批量删除表
    DECLARE @Table NVARCHAR(30)  
    DECLARE tmpCur CURSOR FOR   
    SELECT name FROM sys.objects WHERE TYPE='U' AND name LIKE N'%_QueryLog'  --删除所有含有"_QueryLog"的表
    OPEN tmpCur   
    FETCH NEXT FROM tmpCur INTO @Table  
      
    WHILE @@FETCH_STATUS = 0   
    BEGIN  
        DECLARE @sql VARCHAR(100)  
        SELECT @sql = 'drop table ' + @Table  
        EXEC(@sql)  
        FETCH NEXT FROM tmpCur INTO @Table  
    END  
    CLOSE tmpCur   
    DEALLOCATE tmpCur  

 

posted @ 2017-07-06 09:57  幸福安康  阅读(2248)  评论(0编辑  收藏  举报