您如何以编程方式确定哪些SQL表具有标识列 [英] How do you determine what SQL Tables have an identity column programmatically
本文介绍了您如何以编程方式确定哪些SQL表具有标识列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在SQL Server 2005中创建一个列列表,这些列在T-SQL中具有标识列及其对应的表.
I want to create a list of columns in SQL Server 2005 that have identity columns and their corresponding table in T-SQL.
结果将类似于:
TableName,ColumnName
TableName, ColumnName
推荐答案
针对SQL Server的另一种潜在方法是使用 INFORMATION_SCHEMA视图:
Another potential way to do this for SQL Server, which has less reliance on the system tables (which are subject to change, version to version) is to use the INFORMATION_SCHEMA views:
select COLUMN_NAME, TABLE_NAME
from INFORMATION_SCHEMA.COLUMNS
where COLUMNPROPERTY(object_id(TABLE_SCHEMA+'.'+TABLE_NAME), COLUMN_NAME, 'IsIdentity') = 1
order by TABLE_NAME
这篇关于您如何以编程方式确定哪些SQL表具有标识列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文