SQL SERVER添加表注释、字段注释
--加表注释写法:
EXEC sp_addextendedproperty N'MS_Description', N'用户登录表', N'SCHEMA', N'dbo',N'TABLE', N'IN_ID_LFA_PERSISTENCY';
--例:
EXEC sp_addextendedproperty N'MS_Description', N'注释', N'SCHEMA', N'用户',N'TABLE', N'表名';
--修改表注释:
EXEC sp_updateextendedproperty N'MS_Description', N'注释', N'SCHEMA', N'用户',N'TABLE', N'表名';
--删除表注释:
execute sp_dropextendedproperty 'MS_Description','user','dbo','table','表名称';
--加字段注释写法:
EXEC sp_addextendedproperty N'MS_Description', N'注释', N'SCHEMA', N'用户',N'TABLE', N'表名', N'COLUMN', N'字段';
--例:
EXEC sp_addextendedproperty N'MS_Description', N'DC Code', N'SCHEMA', N'dbo',N'TABLE', N'IN_ID_LFA_PERSISTENCY', N'COLUMN', N'DC';
--修改字段注释
execute sp_updateextendedproperty 'MS_Description','注释内容1', 'user','dbo','table','表名','column','字段名';
--删除字段注释
execute sp_dropextendedproperty 'MS_Description','user','dbo','table','表名','column','字段名';
--查看表的详细信息
SELECT
表名 = Case When A.colorder=1 Then D.name Else '' End,
表说明 = Case When A.colorder=1 Then isnull(F.value,'') Else '' End,
字段序号 = A.colorder,
字段名 = A.name,
类型 = B.name,
字段说明 = isnull(G.[value],''),
标识 = Case When COLUMNPROPERTY( A.id,A.name,'IsIdentity')=1 Then '√'Else '' End,
主键 = Case When exists(SELECT 1 FROM sysobjects Where xtype='PK' and parent_obj=A.id and name in (SELECT name FROM sysindexes WHERE indid in( SELECT indid FROM sysindexkeys WHERE id = A.id AND colid=A.colid))) then '√' else '' end,
占用字节数 = A.Length,
长度 = COLUMNPROPERTY(A.id,A.name,'PRECISION'),
小数位数 = isnull(COLUMNPROPERTY(A.id,A.name,'Scale'),0),
允许空 = Case When A.isnullable=1 Then '√'Else '' End,
默认值 = isnull(E.Text,'')
FROM
syscolumns A Left Join systypes B On A.xusertype=B.xusertype
Inner Join sysobjects D On A.id=D.id and D.xtype='U' and D.name<>'dtproperties'
Left Join syscomments E On A.cdefault=E.id
Left Join sys.extended_properties G On A.id=G.major_id and A.colid=G.minor_id
Left Join sys.extended_properties F On D.id=F.major_id and F.minor_id=0
where d.name='IN_ID_LFA_PERSISTENCY' --如果只查询指定表,加上此条件
Order By
A.id,A.colorder;
--查看表简单信息
SELECT
A.name AS 表名,
B.name AS 表字段,
C.value AS 字段注释
FROM sys.tables A
INNER JOIN sys.columns B ON B.object_id = A.object_id
LEFT JOIN sys.extended_properties C ON C.major_id = B.object_id AND C.minor_id = B.column_id
WHERE A.name = 'sys_user';--表名称
EXEC sp_addextendedproperty N'MS_Description', N'用户登录表', N'SCHEMA', N'dbo',N'TABLE', N'IN_ID_LFA_PERSISTENCY';
--例:
EXEC sp_addextendedproperty N'MS_Description', N'注释', N'SCHEMA', N'用户',N'TABLE', N'表名';
--修改表注释:
EXEC sp_updateextendedproperty N'MS_Description', N'注释', N'SCHEMA', N'用户',N'TABLE', N'表名';
--删除表注释:
execute sp_dropextendedproperty 'MS_Description','user','dbo','table','表名称';
--加字段注释写法:
EXEC sp_addextendedproperty N'MS_Description', N'注释', N'SCHEMA', N'用户',N'TABLE', N'表名', N'COLUMN', N'字段';
--例:
EXEC sp_addextendedproperty N'MS_Description', N'DC Code', N'SCHEMA', N'dbo',N'TABLE', N'IN_ID_LFA_PERSISTENCY', N'COLUMN', N'DC';
--修改字段注释
execute sp_updateextendedproperty 'MS_Description','注释内容1', 'user','dbo','table','表名','column','字段名';
--删除字段注释
execute sp_dropextendedproperty 'MS_Description','user','dbo','table','表名','column','字段名';
--查看表的详细信息
SELECT
表名 = Case When A.colorder=1 Then D.name Else '' End,
表说明 = Case When A.colorder=1 Then isnull(F.value,'') Else '' End,
字段序号 = A.colorder,
字段名 = A.name,
类型 = B.name,
字段说明 = isnull(G.[value],''),
标识 = Case When COLUMNPROPERTY( A.id,A.name,'IsIdentity')=1 Then '√'Else '' End,
主键 = Case When exists(SELECT 1 FROM sysobjects Where xtype='PK' and parent_obj=A.id and name in (SELECT name FROM sysindexes WHERE indid in( SELECT indid FROM sysindexkeys WHERE id = A.id AND colid=A.colid))) then '√' else '' end,
占用字节数 = A.Length,
长度 = COLUMNPROPERTY(A.id,A.name,'PRECISION'),
小数位数 = isnull(COLUMNPROPERTY(A.id,A.name,'Scale'),0),
允许空 = Case When A.isnullable=1 Then '√'Else '' End,
默认值 = isnull(E.Text,'')
FROM
syscolumns A Left Join systypes B On A.xusertype=B.xusertype
Inner Join sysobjects D On A.id=D.id and D.xtype='U' and D.name<>'dtproperties'
Left Join syscomments E On A.cdefault=E.id
Left Join sys.extended_properties G On A.id=G.major_id and A.colid=G.minor_id
Left Join sys.extended_properties F On D.id=F.major_id and F.minor_id=0
where d.name='IN_ID_LFA_PERSISTENCY' --如果只查询指定表,加上此条件
Order By
A.id,A.colorder;
--查看表简单信息
SELECT
A.name AS 表名,
B.name AS 表字段,
C.value AS 字段注释
FROM sys.tables A
INNER JOIN sys.columns B ON B.object_id = A.object_id
LEFT JOIN sys.extended_properties C ON C.major_id = B.object_id AND C.minor_id = B.column_id
WHERE A.name = 'sys_user';--表名称
平淡中储蓄成长
相关文章
发表评论
评论列表
- 这篇文章还没有收到评论,赶紧来抢沙发吧~