怎样去查询SQL 数据库一个表的主键设置
展开全部
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 是否是主键
FROM
sys.columns col left join sys.types typ on (col.system_type_id = typ.system_type_id AND col.user_type_id = typ.user_type_id)
WHERE
col.object_id =
(SELECT object_id FROM sys.tables WHERE name = ' 你的表的名字 ')
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 是否是主键
FROM
sys.columns col left join sys.types typ on (col.system_type_id = typ.system_type_id AND col.user_type_id = typ.user_type_id)
WHERE
col.object_id =
(SELECT object_id FROM sys.tables WHERE name = ' 你的表的名字 ')
追问
如果我的主键是一串18位的数字,这样表的主键数字长度是12的话,是不是我导入数据就会出现主键冲突
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询