码迷,mamicode.com
首页 > 数据库 > 详细

MSSQL 获取数据库字段类型

时间:2014-06-27 16:39:34      阅读:291      评论:0      收藏:0      [点我收藏+]

标签:style   class   blog   code   ext   color   

 1 SELECT
 2    col.name AS 列名,
 3    typ.name as 数据类型,
 4    col.max_length AS 占用字节数,
 5    col.precision AS 数字长度,
 6    col.scale AS 小数位数,
 7    col.is_nullable  AS 是否允许非空,
 8    col.is_identity  AS 是否自增,
 9    case when exists 
10       ( SELECT 1 
11         FROM 
12           sys.indexes idx 
13             join sys.index_columns idxCol 
14             on (idx.object_id = idxCol.object_id)
15          WHERE
16             idx.object_id = col.object_id
17             AND idxCol.index_column_id = col.column_id
18             AND idx.is_primary_key = 1
19        ) THEN 1 ELSE 0 END  AS 是否是主键,
20   isnull(prop.[value],-) AS 说明
21 FROM
22   sys.columns col 
23     left join sys.types typ 
24       on (col.system_type_id = typ.system_type_id)
25     left join sys.extended_properties prop
26       on (col.object_id = prop.major_id AND prop.minor_id = col.column_id)
27 WHERE
28   col.object_id =
29     (SELECT object_id FROM sys.tables WHERE name = band)

 

MSSQL 获取数据库字段类型,布布扣,bubuko.com

MSSQL 获取数据库字段类型

标签:style   class   blog   code   ext   color   

原文地址:http://www.cnblogs.com/smartsensor/p/3809975.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!