首先是获取字段名及注释
代码来自于:http://panyongzheng.iteye.com/blog/1829870
select b.name as column_name, c.value as remarks from sys.tables a left join sys.columns b on a.object_id=b.object_id left join sys.extended_properties c on a.object_id=c.major_id where a.name='TB_CHSS_GRJKDA' and c.minor_id<>0 and b.column_id=c.minor_id and a.schema_id=(select schema_id from sys.schemas where name='dbo')
然后,放到PHP里去做解析的时候会报错:
Fatal error: Unexpected SQL type encountered in calc_string_size
百度是看不到结果的,google了以下,有个人遇到了,也解决了,但是他说的英语,不懂啊,谷歌翻译过来更不懂了
这个人的描述在:http://stackoverflow.com/questions/23479151/getting-metadata-from-table-sql-server-php
然后分析了下,继续搜索了找到一篇文章:
http://m.blog.csdn.net/blog/wendi_0506/38756835
反正最上面那个说英语的,我大概能明白他说的是要做转换,但是从没用过MSSQL的我,一脸茫然啊
下面是正确的方式,主要是对注释字段进行cast转换
select b.name as column_name, cast(c.value as VARCHAR) as remarks from sys.tables a left join sys.columns b on a.object_id=b.object_id left join sys.extended_properties c on a.object_id=c.major_id where a.name='TB_CHSS_GRJKDA' and c.minor_id<>0 and b.column_id=c.minor_id and a.schema_id=(select schema_id from sys.schemas where name='dbo')
------------正 文 已 结 束, 感 谢 您 的 阅 读 (折雨的天空)--------------------
转载请注明本文标题和链接:《mssql获取字段名及注释,以及一系列问题》
发表评论