查询sql server表名、字段名和注释及jdbc连接问题

阅读更多

查询表名和备注:

select c.name,cast(isnull(f.[value], '') as nvarchar(100)) as remark from sys.objects c left join sys.extended_properties f on f.major_id=c.object_id and f.minor_id=0 and f.class=1 where c.type='u'

 查询字段名,属性和备注:

select a.name,a.system_type_id as type, cast(isnull(e.[value],'') as nvarchar(100)) as remark 
from  sys.columns a inner join sys.objects c on a.object_id=c.object_id and c.type='u'
left join sys.extended_properties e on e.major_id=c.object_id 
and e.minor_id=a.column_id and e.class=1 where c.name=?

 在这里使用jdbc连接时会出现:

“com.microsoft.sqlserver.jdbc.SQLServerException: 不支持“variant”数据类型。”
主要是因为jdbc不能将“isnull(e.[value],"")”转换variant类型,可以用cast 或者convet解决,具体用那一个要看 value列中是什么用的数据类型,我这里用的是cast,如:cast(isnull(e.[value],'') as nvarchar(100)) 。

你可能感兴趣的:(jdbc,microsoft,sql,server,sql)