• 删除SqlServer数据表和列的描述


    最近项目有部署到私有云的计划。为了最后的尊严,不能把完整的数据库给对方反向工程了。需要把数据表和列的描述给删掉。

    直接上代码,用的游标处理方式。

     1 --表描述
     2 DECLARE @tn NVARCHAR(50)
     3 DECLARE c CURSOR FOR SELECT t.name FROM sys.tables AS t INNER JOIN sys.extended_properties AS p ON t.[object_id]=p.major_id WHERE t.[type]='U' AND p.minor_id = 0 AND p.[name] = N'MS_Description' ORDER BY t.name
     4 OPEN c
     5 FETCH NEXT FROM c INTO @tn
     6 WHILE @@FETCH_STATUS=0
     7 BEGIN
     8     EXEC sys.sp_dropextendedproperty @name = N'MS_Description' ,@level0type = N'SCHEMA', @level0name = N'gxjt' , @level1type = N'TABLE' ,@level1name = @tn;
     9     FETCH NEXT FROM c INTO @tn
    10 END
    11 CLOSE c
    12 DEALLOCATE c
    13 GO
    14 
    15 --列描述
    16 DECLARE @tn NVARCHAR(50),@cn NVARCHAR(50)
    17 DECLARE c CURSOR FOR SELECT t.name AS tn,l.name AS cn FROM sys.[columns] AS l INNER JOIN sys.extended_properties AS p ON l.[object_id]=p.major_id AND l.column_id=p.minor_id INNER JOIN sys.tables AS t ON l.[object_id]=t.[object_id] WHERE t.[type]='U' AND p.[name] = N'MS_Description' ORDER BY t.name,l.name
    18 OPEN c
    19 FETCH NEXT FROM c INTO @tn,@cn
    20 WHILE @@FETCH_STATUS=0
    21 BEGIN
    22     EXEC sys.sp_dropextendedproperty @name = N'MS_Description' ,@level0type = N'SCHEMA', @level0name = N'gxjt' , @level1type = N'TABLE' ,@level1name = @tn,@level2type = N'COLUMN',@level2name=@cn;
    23     FETCH NEXT FROM c INTO @tn,@cn
    24 END
    25 CLOSE c
    26 DEALLOCATE c
    27 GO
  • 相关阅读:
    IO以及file的一些基本方法
    异常处理和Throwable中的几个方法
    Map的嵌套
    Collections
    Map接口
    Set接口
    React生命周期执行顺序详解
    当面试官问你GET和POST区别的时候,请这么回答.......
    webpack.config.js配置遇到Error: Cannot find module '@babel/core'&&Cannot find module '@babel/plugin-transform-react-jsx' 问题
    前端简单实现校招笔试'作弊监听'功能
  • 原文地址:https://www.cnblogs.com/lmx-102/p/13438961.html
Copyright © 2020-2023  润新知