1个回答
展开全部
表不能备注,表中的字段可以备注,下面的代码可以读取表中字段的备注
Declare @tblName nvarchar(1000)
set @tblName='表名'
declare @TblID int
set @TblID=(select [object_id] as tblID from sys.all_objects where [type] ='U' and [name]<>'dtproperties' and [name]=@tblName)
select syscolumns.name as ColumnName,
systypes.name as ColumnType,
syscolumns.length as ColumnLength,
(SELECT [value] FROM ::fn_listextendedproperty(NULL, 'user', 'dbo', 'table', object_name(@TblID), 'column', syscolumns.name) as e where e.name='MS_Description') as ColumnDescription
from sysColumns
left join sysTypes on sysTypes.xtype = sysColumns.xtype and sysTypes.xusertype = sysColumns.xusertype
left join sysobjects on sysobjects.id = syscolumns.cdefault and sysobjects.type='D'
left join syscomments on syscomments.id = sysobjects.id
where syscolumns.id=@TblID
表名那换成你想读取的表就行
Declare @tblName nvarchar(1000)
set @tblName='表名'
declare @TblID int
set @TblID=(select [object_id] as tblID from sys.all_objects where [type] ='U' and [name]<>'dtproperties' and [name]=@tblName)
select syscolumns.name as ColumnName,
systypes.name as ColumnType,
syscolumns.length as ColumnLength,
(SELECT [value] FROM ::fn_listextendedproperty(NULL, 'user', 'dbo', 'table', object_name(@TblID), 'column', syscolumns.name) as e where e.name='MS_Description') as ColumnDescription
from sysColumns
left join sysTypes on sysTypes.xtype = sysColumns.xtype and sysTypes.xusertype = sysColumns.xusertype
left join sysobjects on sysobjects.id = syscolumns.cdefault and sysobjects.type='D'
left join syscomments on syscomments.id = sysobjects.id
where syscolumns.id=@TblID
表名那换成你想读取的表就行
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询