大佬教程收集整理的这篇文章主要介绍了SqlServer字段说明添加,查询,修改! 查询字段名称和类型。,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
1.查询两个表的字段说明
SELECT t.[name] AS [表名],c.[name] AS [字段名],cast(ep.[value]
as varchar(100)) AS [字段说明]
FROM sys.tables AS t INNER JOIN sys.columns
AS c ON t.object_id = c.object_id LEFT JOIN sys.extended_properties AS ep
ON ep.@H_653_8@major_id = c.object_id AND ep.@H_653_8@minor_id = c.COLUMN_ID WHERE ep.class =1
and t.[name]='table1' or t.[name]='table2'
and c.[name] in ('table2字段','table2字段')
or c.[name] in ('table1字段,'table1字段')
2.添加字段的名称
EXEC
sys.sp_addextendedproperty @name=N'MS_Description',
@value=N'字段说明' , @level0type=N'scheR_518_11845@A',@level0name=N'dbo',
@level1type=N'TABLE',@level1name=N'表名', @level2type=N'columN',
@level2name=N'字段名'
GO
3.修改字段的名称
BEGIN transaCTION
GO
DECLARE @v sql_variant
SET @v = N'说明信息'
EXECUTE sys.sp_updateextendedproperty N'MS_Description',
@v, N'scheR_518_11845@A',N'dbo',N'TABLE',N'表名, N'columN', N'字段名'
GO
COMMIT
4.查询数据库字段信息,和类型
SELEct a.name as zdname,a.length,b.name as zdtype from sysColumns a,systypes b,sysobjects c
where a.xtype=b.xtype and a.id=c.id and c.name= 'table' --没有过滤系统字段信息
SELEct a.name,b.name from sysColumns a,sysobjects c
where a.xtype=b.xtype and a.id=c.id and c.name= 'table'
AND B.NAME!='SYSNAME' --过滤了系统字段信息
where a.xtype=b.xtype and a.id=c.id and c.name= 'table' and charindex('sysname',b.name) = 0
--过滤了系统字段信息
以上是大佬教程为你收集整理的SqlServer字段说明添加,查询,修改! 查询字段名称和类型。全部内容,希望文章能够帮你解决SqlServer字段说明添加,查询,修改! 查询字段名称和类型。所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。