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

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
T
Threatpost
Latest news
Latest news
N
News | PayPal Newsroom
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Help Net Security
Help Net Security
D
Darknet – Hacking Tools, Hacker News & Cyber Security
AI
AI
Simon Willison's Weblog
Simon Willison's Weblog
TaoSecurity Blog
TaoSecurity Blog
The Last Watchdog
The Last Watchdog
L
LINUX DO - 热门话题
Google DeepMind News
Google DeepMind News
T
Threat Research - Cisco Blogs
O
OpenAI News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
The Exploit Database - CXSecurity.com
NISL@THU
NISL@THU
Application and Cybersecurity Blog
Application and Cybersecurity Blog
S
Securelist
小众软件
小众软件
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Martin Fowler
Martin Fowler
S
SegmentFault 最新的问题
Cisco Talos Blog
Cisco Talos Blog
云风的 BLOG
云风的 BLOG
AWS News Blog
AWS News Blog
GbyAI
GbyAI
N
News and Events Feed by Topic
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
美团技术团队
Engineering at Meta
Engineering at Meta
A
About on SuperTechFans
博客园 - 三生石上(FineUI控件)
S
Schneier on Security
博客园 - 聂微东
V2EX - 技术
V2EX - 技术
T
Troy Hunt's Blog
SecWiki News
SecWiki News
S
Secure Thoughts
B
Blog RSS Feed
Hugging Face - Blog
Hugging Face - Blog
WordPress大学
WordPress大学
腾讯CDC
H
Heimdal Security Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Apple Machine Learning Research
Apple Machine Learning Research
月光博客
月光博客
www.infosecurity-magazine.com
www.infosecurity-magazine.com
P
Privacy International News Feed

博客园 - Dot-Boy

突然发现我的时间停留在2010年5月14日 vc中遇到错误提示:nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __endthreadex VSS配置外部对比工具Beyond Compare C#程序集使用强名字(Strong Name)签名/强名称签名 应用程序试图执行安全策略不允许的操作。要授予此应用程序所需的权限,请与系统管理员联系,或在配置文件中更改该应用程序的信任级别 C#程序脱离.net框架的多种方法与应用 理解 Thread.Sleep 函数 SQL2005安装问题 性能监视器计数器要求 (错误) 及超强解决办法 sqlserver 大小写敏感 Lambda 表达式 SQL Server 2005 中的分区表和索引 Analysis Services 2005中数据完整性处理(转载) 在 Microsoft Windows Server 2003 上配置对 SQL Server 2005 Analysis Services 的 HTTP 访问 Programatically recycle an IIS application pool jquery 弹出浮层(div) + 遮蔽层 - Dot-Boy 防止重复提交的方式 - Dot-Boy - 博客园 解决mysqlclient无法转换无效的时间类型 - Dot-Boy - 博客园 实现在表单内按回车键,执行指定按钮的事件 - Dot-Boy - 博客园 计算程序段运行时间
SQL Server 中取得字段说明(转载)
Dot-Boy · 2009-08-24 · via 博客园 - Dot-Boy

如何从SQL Server 中取得字段说明

SQL Server 2000

你可以在企业管理器中增加字段说明,也可以使用下面的代码:

EXEC sp_addextendedproperty 
    
'MS_Description'
    
'some description'
    
'user'
    dbo, 
    
'table'
    table_name, 
    
'column'
    column_name

现在,你就可以得到通过下面的代码得到字段说明:

SELECT 
    
[Table Name] = i_s.TABLE_NAME, 
    
[Column Name] = i_s.COLUMN_NAME, 
    
[Description] = s.value 
FROM 
    INFORMATION_SCHEMA.COLUMNS i_s 
LEFT OUTER JOIN 
    sysproperties s 
ON 
    s.id 
= OBJECT_ID(i_s.TABLE_SCHEMA+'.'+i_s.TABLE_NAME) 
    
AND s.smallid = i_s.ORDINAL_POSITION 
    
AND s.name = 'MS_Description' 
WHERE 
    
OBJECTPROPERTY(OBJECT_ID(i_s.TABLE_SCHEMA+'.'+i_s.TABLE_NAME), 'IsMsShipped')=0 
    
-- AND i_s.TABLE_NAME = 'table_name' 
ORDER BY 
    i_s.TABLE_NAME, i_s.ORDINAL_POSITION

如果你只关心某一张表,那么上面的TSQL中的注释部份对你就非常有帮助。反过来就会给你所有表中的所有字段。

如果你只需要所有有说明的表,你可以把out join 改成 inner join

SELECT 
    
[Table Name] = i_s.TABLE_NAME, 
    
[Column Name] = i_s.COLUMN_NAME, 
    
[Description] = s.value 
FROM 
    INFORMATION_SCHEMA.COLUMNS i_s 
INNER JOIN 
    sysproperties s 
ON 
    s.id 
= OBJECT_ID(i_s.TABLE_SCHEMA+'.'+i_s.TABLE_NAME) 
    
AND s.smallid = i_s.ORDINAL_POSITION 
    
AND s.name = 'MS_Description' 
WHERE 
    
OBJECTPROPERTY(OBJECT_ID(i_s.TABLE_SCHEMA+'.'+i_s.TABLE_NAME), 'IsMsShipped')=0 
ORDER BY 
    i_s.TABLE_NAME, i_s.ORDINAL_POSITION

SQL Server 2005

在SQL Server 2005 中 sysproperties 表已被废弃,所以上面的代码都不能用。幸运的是他们还是增加了一个系统表给我们 sys.extended_properties,这张表和 sysproperties基本上相似。

SELECT 
    
[Table Name] = OBJECT_NAME(c.object_id), 
    
[Column Name] = c.name, 
    
[Description] = ex.value 
FROM 
    sys.columns c 
LEFT OUTER JOIN 
    sys.extended_properties ex 
ON 
    ex.major_id 
= c.object_id 
    
AND ex.minor_id = c.column_id 
    
AND ex.name = 'MS_Description' 
WHERE 
    
OBJECTPROPERTY(c.object_id'IsMsShipped')=0 
    
-- AND OBJECT_NAME(c.object_id) = 'your_table' 
ORDER 
    
BY OBJECT_NAME(c.object_id), c.column_id

和SQL Server 2000一样,你可以使用注释部份来返回某一张表。
Microsoft Access
在Access中,你可以使用下面的ASP代码来得到某一个字段的说明

<
    
on error resume next 
    
Set Catalog = CreateObject("ADOX.Catalog"
    Catalog.ActiveConnection 
= "Provider=Microsoft.Jet.OLEDB.4.0;" & _ 
        
"Data Source=<path>\<file>.mdb" 

    dsc 
= Catalog.Tables("table_name").Columns("column_name").Properties("Description").Value 

    
if err.number <> 0 then 
        Response.Write 
"&lt;" & err.description & "&gt;" 
    
else 
        Response.Write 
"Description = " & dsc 
    
end if 
    
Set Catalog = nothing 
%
>