zoukankan      html  css  js  c++  java
  • SQL 批量删除表

      /*--------------------------------  
      
    功能说明:  批量DropTable  
      
    使用说明:  使用时一定要小心,因为删选表的where条件是like所有必须保证where  
      
    后的like确定与你要删除表名相匹配  
      
    ---------------------------------*/  
      
    --------参数定义-------------------  
      
    DECLARE @tableName AS Nvarchar(50) --查询表名条件(小心!,确保like条件是你要Drop的表.TableName尽量精确)  
      
    SET @tableName='hduCV1'            //此处为待删除的表前缀
      
    --------------------------------------  
      
    --SELECT name FROM sys.tables   WHERE name LIKE '%'+@tableName+'%' --查询出要删除表的名称  
      
    IF @tableName='' SET @tableName='tableName'--初始化TableName为tableName,防止@tableName为空  
      
    DECLARE @tableNames AS Nvarchar(3000)  
      
    DECLARE @sql AS Nvarchar(3000)  
      
    SET @tableNames=  
      
    (SELECT ','+name FROM sys.tables   WHERE name LIKE '%'+@tableName+'%'  FOR XML PATH(''))  
      
    SET @tableNames= Stuff(@tableNames,1,1,'')  
      
    SET @sql='DROP TABLE '+@tableNames  
      
    EXEC(@sql) 
    

      转载:http://yangjingblog.iteye.com/blog/1095027

  • 相关阅读:
    Kth Ancestor 第k个祖先问题
    centOS 6.4挂载centOS分区
    上阶段学习总结
    code testing
    Helo~
    leetcode--Maximum Subarray
    leetcode--Climbing Stairs
    leetcode--Search Insert Position
    leetcode--Best Time to Buy and Sell Stock III
    leetcode--Best Time to Buy and Sell Stock II
  • 原文地址:https://www.cnblogs.com/mrethan/p/4513997.html
Copyright © 2011-2022 走看看