惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - 俩醒叁醉

ASP.NET MVC 4 WebAPI. Support Areas in HttpControllerSelector SQL2000安装问题(转) - 俩醒叁醉 sql server 2008安装需要一直重启。但重启后又没有达到效果。 - 俩醒叁醉 为数据库中所有的用户数据表生成分页存储过程 __doPostBack方法解析 - 俩醒叁醉 如何在三个月掌握三年的经验(转载&&笔记) - 俩醒叁醉 jQuery Ajax的使用 JQuery资源网站 - 俩醒叁醉 Cookie跨域、虚拟目录 深入分析跨域cookie的问题 CnBlogsDotText使用实例 - 俩醒叁醉 轻松搭建博客平台-开源ASP.NET 博客Subtext 的安装 表达式目录树(源MSDN) Web 2.0 编程思想:16条法则 Control Adapter 以下代码提供查询数据库中是否存在某个值 URL Routing MVC Controllers和Forms验证 CSharp——Lambda 表达式
SQL 2005 字段备注获取
俩醒叁醉 · 2009-08-25 · via 博客园 - 俩醒叁醉

  实际开发中经常为数据字段备注而烦恼,为此写了如下存储过程,一方便查看数据库备注信息.

 1  
 2 create proc [dbo].[GenerateDataDictionaryByTableName]
 3 @tableName  nvarchar(255)
 4 as
 5 begin
 6 --获取数据表名
 7 declare  @tableid int
 8 declare mycursor Cursor
 9 for select object_id from sys.objects where type='U' and  name<>'dtproperties' and name LIKE '%'+ @tableName+'%'
10 --获取字段名称、标识、字段序号、占用字节数、小数位数、允许空等
11 open mycursor
12 fetch next from mycursor into @tableid
13 while(@@fetch_status=0) 
14 begin 
15     SELECT object_name(@tableid) AS 表名,VALUE AS 表说明 FROM sys.extended_properties 
16     WHERE NAME='MS_Description' AND MAJOR_ID=@tableid AND MINOR_ID=0;
17     select 
18         col.colorder 字段序号,
19         col.name 字段名,
20         t.name 类型,
21         col.length 占用字节数,
22         COLUMNPROPERTY(col.id,col.name,'PRECISION') as 长度,
23         isnull(COLUMNPROPERTY(col.id,col.name,'Scale'),0) as 小数位数,
24         (case when 
25             (SELECT count(*)
26                 FROM sysobjects
27                 WHERE (name in
28                     (SELECT name
29                         FROM sysindexes
30                         WHERE (id = col.id) 
31                             AND (indid in
32                                     (SELECT indid
33                                      FROM sysindexkeys
34                                      WHERE (id = col.id) AND (colid in
35                                             ( SELECT colid
36                                               FROM syscolumns
37                                               WHERE (id = col.id)
38                                                     AND (name = col.name)
39                                               ))
40                                      )
41                                   )
42                    )) AND
43                    (xtype = 'PK')
44               )>0 
45          then '' else '' end) 主键,
46         (case when COLUMNPROPERTY(col.id,col.name,'IsIdentity')=1 then ''else '' end) 标识,
47         (case when col.isnullable=1 then ''else '' end) 允许空,
48         isnull(expro.[value],'') AS 字段说明
49     from sys.syscolumns as col
50     left join sys.systypes as t on col.xtype = t.xusertype
51     left join sys.extended_properties as expro on col.id=expro.major_id AND col.colid = expro.minor_id
52     where id = @tableid 
53     fetch next from mycursor into @tableid
54 end
55 close mycursor
56 deallocate mycursor 
57 end

  在需要查看指定表描述时,输入如下语句:

exec [GenerateDataDictionaryByTableName] N'T_INTE_'

该存储过程会搜索当前数据库中表名包含传入的参数字符串,并返回符合条件的所有表的备注信息。如下返回形如: