关闭

C# 获取数据库字段类型

1530人阅读 评论(0) 收藏 举报
分类:
SELECT
col.name AS 列名,
typ.name as 数据类型,
col.max_length AS 占用字节数,
col.precision AS 数字长度,
col.scale AS 小数位数,
col.is_nullable AS 是否允许非空,
col.is_identity AS 是否自增,
case when exists
( SELECT 1
FROM
sys.indexes idx
join sys.index_columns idxCol
on (idx.object_id = idxCol.object_id)
WHERE
idx.object_id = col.object_id
AND idxCol.index_column_id = col.column_id
AND idx.is_primary_key = 1
) THEN 1 ELSE 0 END AS 是否是主键,
isnull(prop.[value],'-') AS 说明
FROM
sys.columns col
left joinsys.types typ
on (col.system_type_id = typ.system_type_id)
left joinsys.extended_properties prop
on (col.object_id = prop.major_id AND prop.minor_id = col.column_id)
WHERE
col.object_id =
(SELECT object_id FROM sys.tablesWHERE name = 'test_table')
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:194657次
    • 积分:1872
    • 等级:
    • 排名:千里之外
    • 原创:25篇
    • 转载:59篇
    • 译文:0篇
    • 评论:17条
    文章分类
    最新评论