如何获取SQL Server中具有标识插入的表是否存在主键? [英] How to fetch whether primary key exists for tables with identity insert in SQL server?
本文介绍了如何获取SQL Server中具有标识插入的表是否存在主键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何获取在Sql Server中具有标识插入的表是否存在主键?
我使用下面的查询来获取具有标识插入的表。我想检查相同查询是否存在主键。
How to fetch whether Primary Key exists for tables with Identity Insert in Sql Server?
I am using below query to fetch tables with Identity insert. I want to check whether Primary Key exists for the same query wise.
select
c.TABLE_SCHEMA ,
t.TABLE_NAME ,
case when charindex('.', c.COLUMN_NAME) > 0 then '"' + c.COLUMN_NAME + '"';
else c.COLUMN_NAME end ,
c.DATA_TYPE ,
NUMERIC_PRECISION,
NUMERIC_SCALE
from
information_schema.columns c
inner join
information_schema.tables t
on t.TABLE_NAME = c.TABLE_NAME
where
columnproperty(object_id(c.TABLE_NAME),c.COLUMN_NAME, 'IsIdentity') = 1
我尝试了什么:
尝试查询以获取具有以下查询的标识插入列的表
What I have tried:
Tried query to fetch Tables having columns with Identity Insert with below query
select
c.TABLE_SCHEMA ,
t.TABLE_NAME ,
case when charindex('.', c.COLUMN_NAME) > 0 then '"' + c.COLUMN_NAME +'"'
else c.COLUMN_NAME end ,
c.DATA_TYPE ,
NUMERIC_PRECISION,
NUMERIC_SCALE
from
information_schema.columns c
inner join
information_schema.tables t
on t.TABLE_NAME = c.TABLE_NAME
where
columnproperty(object_id(c.TABLE_NAME),c.COLUMN_NAME, 'IsIdentity') = 1
推荐答案
检查此查找所有主键和标识列 [ ^ ]
这篇关于如何获取SQL Server中具有标识插入的表是否存在主键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文