博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
获取、增加、修改、删除sqlserver字段描述及快速查看表字段与描述
阅读量:5043 次
发布时间:2019-06-12

本文共 13244 字,大约阅读时间需要 44 分钟。

先看添加与删除字段描述

EXEC sys.sp_addextendedproperty @name = N'MS_Description',    --添加Type字段说明     @value = N'屏蔽类型对应值(类型对应Id)',     @level0type = N'SCHEMA',     @level0name = N'dbo',     @level1type = N'TABLE',     @level1name = N'ForbiddenType',     @level2type = N'COLUMN',     @level2name = N'TypeId'   --删除表中列Type的描述属性:                               EXEC sp_dropextendedproperty 'MS_Description',     'SCHEMA',     dbo,     'TABLE',     'ForbiddenType',     'COLUMN',     TYPE

看下面的实例:

--创建表及描述信息 create table 表(a1 varchar(10),a2 char(2)) --为表添加描述信息 EXECUTE sp_addextendedproperty N'MS_Description', '人员信息表', N'user', N'dbo', N'table', N'表', NULL, NULL

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'生成记录表' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'CrabRequisition'

GO

--为字段a1添加描述信息 EXECUTE sp_addextendedproperty N'MS_Description', '姓名', N'user', N'dbo', N'table', N'表', N'column', N'a1'EXECUTE sp_addextendedproperty N'MS_Description', '测试', N'user', N'dbo', N'table', N'HR_Employees', N'column', N'test' --为字段a2添加描述信息 EXECUTE sp_addextendedproperty N'MS_Description', '性别', N'user', N'dbo', N'table', N'表', N'column', N'a2' --更新表中列a1的描述属性: EXEC sp_updateextendedproperty 'MS_Description','字段1','user',dbo,'table','表','column',a1 --删除表中列a1的描述属性: EXEC sp_dropextendedproperty 'MS_Description','user',dbo,'table','表','column',a1

 

--表描述  SELECT    tbs.name 表名   ,ds.value 描述FROM sys.extended_properties dsLEFT JOIN sysobjects tbs    ON ds.major_id = tbs.idWHERE ds.minor_id = 0AND tbs.name = 'Warrant_BaseInfo';--表名
--快速查看表结构  SELECT    CASE        WHEN col.colorder = 1 THEN obj.name        ELSE ''    END AS 表名   ,col.colorder AS 序号   ,col.name AS 列名   ,ISNULL(ep.[value], '') AS 列说明   ,t.name AS 数据类型   ,col.length AS 长度   ,ISNULL(COLUMNPROPERTY(col.id, col.name, 'Scale'), 0) AS 小数位数   ,CASE        WHEN COLUMNPROPERTY(col.id, col.name, 'IsIdentity') = 1 THEN '√'        ELSE ''    END AS 标识   ,CASE        WHEN EXISTS (SELECT                    1                FROM dbo.sysindexes si                INNER JOIN dbo.sysindexkeys sik                    ON si.id = sik.id                    AND si.indid = sik.indid                INNER JOIN dbo.syscolumns sc                    ON sc.id = sik.id                    AND sc.colid = sik.colid                INNER JOIN dbo.sysobjects so                    ON so.name = si.name                    AND so.xtype = 'PK'                WHERE sc.id = col.id                AND sc.colid = col.colid) THEN '√'        ELSE ''    END AS 主键   ,CASE        WHEN col.isnullable = 1 THEN '√'        ELSE ''    END AS 允许空   ,ISNULL(comm.text, '') AS 默认值FROM dbo.syscolumns colLEFT JOIN dbo.systypes t    ON col.xtype = t.xusertypeINNER JOIN dbo.sysobjects obj    ON col.id = obj.id        AND obj.xtype = 'U'        AND obj.status >= 0LEFT JOIN dbo.syscomments comm    ON col.cdefault = comm.idLEFT JOIN sys.extended_properties ep    ON col.id = ep.major_id        AND col.colid = ep.minor_id        AND ep.name = 'MS_Description'LEFT JOIN sys.extended_properties epTwo    ON obj.id = epTwo.major_id        AND epTwo.minor_id = 0        AND epTwo.name = 'MS_Description'WHERE obj.name = 'Ath_LoanApply_tbl'--表名  ORDER BY col.colorder;

 

IF (( SELECT        COUNT(*)    FROM fn_listextendedproperty('MS_Description',    'SCHEMA', N'dbo',    'TABLE', N'Fct_Order',    'COLUMN', N'Carrier'))> 0) EXEC sp_updateextendedproperty    @name = N'MS_Description',                                    @value = N'承运商',                                    @level0type = 'SCHEMA',                                    @level0name = N'dbo',                                    @level1type = 'TABLE',                                    @level1name = N'Fct_Order',                                    @level2type = 'COLUMN',                                    @level2name = N'Carrier' ELSE EXEC sp_addextendedproperty    @name = N'MS_Description',                                                                                                @value = N'承运商',                                                                                                @level0type = 'SCHEMA',                                                                                                @level0name = N'dbo',                                                                                                @level1type = 'TABLE',                                                                                                @level1name = N'Fct_Order',                                                                                                @level2type = 'COLUMN',                                                                                                @level2name = N'Carrier'GO

 

PrePackage_HeaderIF NOT EXISTS ( SELECT  NULL                FROM    dbo.sysobjects                WHERE   id = OBJECT_ID(N'[PrePackage_Header]')                        AND OBJECTPROPERTY(id, 'IsTable') = 1 )    BEGIN        CREATE TABLE PrePackage_Header            (              PrePackagedId [UNIQUEIDENTIFIER] NOT NULL ,              WarehouseId [UNIQUEIDENTIFIER] NOT NULL ,              PrePackagedCodeNumber [VARCHAR](50) NOT NULL ,              PrePackagedBarCodeNumber [VARCHAR](50) NOT NULL ,              PrePackagedName [VARCHAR](50) NOT NULL ,              Disabled INT                NOT NULL                CONSTRAINT [DF_PrePackage_Header_Disabled] DEFAULT ( (0) ) ,              Rec_CreateTime DATETIME                NULL                CONSTRAINT [DF_PrePackage_Header_Rec_CreateTime]                DEFAULT ( GETDATE() ) ,              Rec_CreateBy [VARCHAR](50) NULL ,              Rec_ModifyTime [DATETIME] NULL ,              Rec_ModifyBy [VARCHAR](50) NULL ,              CONSTRAINT [PK_PrePackage_Header] PRIMARY KEY CLUSTERED                ( PrePackagedId ASC )                WITH ( PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF,                       IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON,                       ALLOW_PAGE_LOCKS = ON ) ON [PRIMARY]            )        ON  [PRIMARY];                EXEC sys.sp_addextendedproperty @name = N'MS_Description',            @value = N'预包装管理Id', @level0type = N'SCHEMA', @level0name = N'dbo',            @level1type = N'TABLE', @level1name = N'PrePackage_Header',            @level2type = N'COLUMN', @level2name = N'PrePackagedId';        EXEC sys.sp_addextendedproperty @name = N'MS_Description',            @value = N'仓库Id', @level0type = N'SCHEMA', @level0name = N'dbo',            @level1type = N'TABLE', @level1name = N'PrePackage_Header',            @level2type = N'COLUMN', @level2name = N'WarehouseId';        EXEC sys.sp_addextendedproperty @name = N'MS_Description',            @value = N'预包装编码', @level0type = N'SCHEMA', @level0name = N'dbo',            @level1type = N'TABLE', @level1name = N'PrePackage_Header',            @level2type = N'COLUMN', @level2name = N'PrePackagedCodeNumber';        EXEC sys.sp_addextendedproperty @name = N'MS_Description',            @value = N'预包装条码', @level0type = N'SCHEMA', @level0name = N'dbo',            @level1type = N'TABLE', @level1name = N'PrePackage_Header',            @level2type = N'COLUMN', @level2name = N'PrePackagedBarCodeNumber';        EXEC sys.sp_addextendedproperty @name = N'MS_Description',            @value = N'预包装名称', @level0type = N'SCHEMA', @level0name = N'dbo',            @level1type = N'TABLE', @level1name = N'PrePackage_Header',            @level2type = N'COLUMN', @level2name = N'PrePackagedName';                    EXEC sys.sp_addextendedproperty @name = N'MS_Description',            @value = N'是否禁用', @level0type = N'SCHEMA', @level0name = N'dbo',            @level1type = N'TABLE', @level1name = N'PrePackage_Header',            @level2type = N'COLUMN', @level2name = N'Disabled';        EXEC sys.sp_addextendedproperty @name = N'MS_Description',            @value = N'创建时间', @level0type = N'SCHEMA', @level0name = N'dbo',            @level1type = N'TABLE', @level1name = N'PrePackage_Header',            @level2type = N'COLUMN', @level2name = N'Rec_CreateTime';        EXEC sys.sp_addextendedproperty @name = N'MS_Description',            @value = N'创建人', @level0type = N'SCHEMA', @level0name = N'dbo',            @level1type = N'TABLE', @level1name = N'PrePackage_Header',            @level2type = N'COLUMN', @level2name = N'Rec_CreateBy';        EXEC sys.sp_addextendedproperty @name = N'MS_Description',            @value = N'修改时间', @level0type = N'SCHEMA', @level0name = N'dbo',            @level1type = N'TABLE', @level1name = N'PrePackage_Header',            @level2type = N'COLUMN', @level2name = N'Rec_ModifyTime';        EXEC sys.sp_addextendedproperty @name = N'MS_Description',            @value = N'修改人', @level0type = N'SCHEMA', @level0name = N'dbo',            @level1type = N'TABLE', @level1name = N'PrePackage_Header',            @level2type = N'COLUMN', @level2name = N'Rec_ModifyBy';        EXEC sys.sp_addextendedproperty @name = N'MS_Description',            @value = N'预包装管理主表', @level0type = N'SCHEMA', @level0name = N'dbo',            @level1type = N'TABLE', @level1name = N'PrePackage_Header';    END;GOPrePackage_DetailIF NOT EXISTS ( SELECT  NULL                FROM    dbo.sysobjects                WHERE   id = OBJECT_ID(N'[PrePackage_Detail]')                        AND OBJECTPROPERTY(id, 'IsTable') = 1 )    BEGIN        CREATE TABLE PrePackage_Detail            (              PrePackage_DetailId [UNIQUEIDENTIFIER] NOT NULL ,              PrePackagedId [UNIQUEIDENTIFIER] NOT NULL ,              GoodsId [UNIQUEIDENTIFIER] NULL ,              GoodsCode [VARCHAR](50) NULL ,              Qunatity DECIMAL(18, 2) NOT NULL ,              Disabled INT                NOT NULL                CONSTRAINT [DF_PrePackage_Detail_Disabled] DEFAULT ( (0) ) ,              Rec_CreateTime DATETIME                NULL                CONSTRAINT [DF_PrePackage_Detail_Rec_CreateTime]                DEFAULT ( GETDATE() ) ,              Rec_CreateBy [VARCHAR](50) NULL ,              Rec_ModifyTime [DATETIME] NULL ,              Rec_ModifyBy [VARCHAR](50) NULL ,              CONSTRAINT [PK_PrePackage_Detail] PRIMARY KEY CLUSTERED                ( PrePackage_DetailId ASC )                WITH ( PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF,                       IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON,                       ALLOW_PAGE_LOCKS = ON ) ON [PRIMARY]            )        ON  [PRIMARY];                EXEC sys.sp_addextendedproperty @name = N'MS_Description',            @value = N'预包装明细Id', @level0type = N'SCHEMA', @level0name = N'dbo',            @level1type = N'TABLE', @level1name = N'PrePackage_Detail',            @level2type = N'COLUMN', @level2name = N'PrePackage_DetailId';        EXEC sys.sp_addextendedproperty @name = N'MS_Description',            @value = N'货品编码', @level0type = N'SCHEMA', @level0name = N'dbo',            @level1type = N'TABLE', @level1name = N'PrePackage_Detail',            @level2type = N'COLUMN', @level2name = N'GoodsCode';        EXEC sys.sp_addextendedproperty @name = N'MS_Description',            @value = N'货品Id', @level0type = N'SCHEMA', @level0name = N'dbo',            @level1type = N'TABLE', @level1name = N'PrePackage_Detail',            @level2type = N'COLUMN', @level2name = N'GoodsId';        EXEC sys.sp_addextendedproperty @name = N'MS_Description',            @value = N'数量', @level0type = N'SCHEMA', @level0name = N'dbo',            @level1type = N'TABLE', @level1name = N'PrePackage_Detail',            @level2type = N'COLUMN', @level2name = N'Qunatity';                    EXEC sys.sp_addextendedproperty @name = N'MS_Description',            @value = N'是否删除', @level0type = N'SCHEMA', @level0name = N'dbo',            @level1type = N'TABLE', @level1name = N'PrePackage_Detail',            @level2type = N'COLUMN', @level2name = N'Disabled';        EXEC sys.sp_addextendedproperty @name = N'MS_Description',            @value = N'创建时间', @level0type = N'SCHEMA', @level0name = N'dbo',            @level1type = N'TABLE', @level1name = N'PrePackage_Detail',            @level2type = N'COLUMN', @level2name = N'Rec_CreateTime';        EXEC sys.sp_addextendedproperty @name = N'MS_Description',            @value = N'创建人', @level0type = N'SCHEMA', @level0name = N'dbo',            @level1type = N'TABLE', @level1name = N'PrePackage_Detail',            @level2type = N'COLUMN', @level2name = N'Rec_CreateBy';        EXEC sys.sp_addextendedproperty @name = N'MS_Description',            @value = N'修改时间', @level0type = N'SCHEMA', @level0name = N'dbo',            @level1type = N'TABLE', @level1name = N'PrePackage_Detail',            @level2type = N'COLUMN', @level2name = N'Rec_ModifyTime';        EXEC sys.sp_addextendedproperty @name = N'MS_Description',            @value = N'修改人', @level0type = N'SCHEMA', @level0name = N'dbo',            @level1type = N'TABLE', @level1name = N'PrePackage_Detail',            @level2type = N'COLUMN', @level2name = N'Rec_ModifyBy';        EXEC sys.sp_addextendedproperty @name = N'MS_Description',            @value = N'预包装明细', @level0type = N'SCHEMA', @level0name = N'dbo',            @level1type = N'TABLE', @level1name = N'PrePackage_Detail';    END;GO
View Code

 

转载于:https://www.cnblogs.com/shy1766IT/p/5267797.html

你可能感兴趣的文章
MySql执行分析
查看>>
git使用中的问题
查看>>
yaml文件 .yml
查看>>
linux字符集修改
查看>>
phpcms 添加自定义表单 留言
查看>>
mysql 优化
查看>>
读书笔记 ~ Nmap渗透测试指南
查看>>
WCF 配置文件
查看>>
动态调用WCF服务
查看>>
oracle导出/导入 expdp/impdp
查看>>
类指针
查看>>
css修改滚动条样式
查看>>
2018.11.15 Nginx服务器的使用
查看>>
Kinect人机交互开发实践
查看>>
百度编辑器UEditor ASP.NET示例Demo 分类: ASP.NET...
查看>>
JAVA 技术类分享(二)
查看>>
android客户端向服务器发送请求中文乱码的问
查看>>
Symfony翻译教程已开课
查看>>
TensorFlow2.0矩阵与向量的加减乘
查看>>
NOIP 2010题解
查看>>