首先是获取字段名及注释
代码来自于: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')
Fatal error: Unexpected SQL type encountered in calc_string_size
这个人的描述在: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')