如何在MSSQL 2000中确定列是否是标识列?

时间:2022-11-30 09:35:47

I want to do this in code, not with ALT+F1.

我想用代码来做,而不是用ALT+F1。

4 个解决方案

#1


58  

You can also do it this way:

你也可以这样做:

select columnproperty(object_id('mytable'),'mycolumn','IsIdentity')

Returns 1 if it's an identity, 0 if not.

如果是恒等式,返回1,如果不是,返回0。

#2


15  

sp_help tablename 

In the output look for something like this:

在输出中查找如下内容:

 Identity     Seed     Increment     Not For Replication    
 -----------  -------  ------------  ---------------------- 
 userid       15500    1             0        

#3


4  

Adjust the WHERE clause to suit:

调整WHERE子句以适应:

select
    a.name as TableName,
    b.name as IdentityColumn
from
    sysobjects a inner join syscolumns b on a.id = b.id
where
    columnproperty(a.id, b.name, 'isIdentity') = 1
    and objectproperty(a.id, 'isTable') = 1

#4


0  

As expansion on @Blogbeard's answer

作为对@Blogbeard的回答的扩展

If you like pure query and not inbuilt functions

如果您喜欢纯查询,而不是内置函数。

select col_name(sys.all_objects.object_id, column_id) as id from sys.identity_columns 
join sys.all_objects on sys.identity_columns.object_id = sys.all_objects.object_id
where sys.all_objects.name = 'system_files'

#1


58  

You can also do it this way:

你也可以这样做:

select columnproperty(object_id('mytable'),'mycolumn','IsIdentity')

Returns 1 if it's an identity, 0 if not.

如果是恒等式,返回1,如果不是,返回0。

#2


15  

sp_help tablename 

In the output look for something like this:

在输出中查找如下内容:

 Identity     Seed     Increment     Not For Replication    
 -----------  -------  ------------  ---------------------- 
 userid       15500    1             0        

#3


4  

Adjust the WHERE clause to suit:

调整WHERE子句以适应:

select
    a.name as TableName,
    b.name as IdentityColumn
from
    sysobjects a inner join syscolumns b on a.id = b.id
where
    columnproperty(a.id, b.name, 'isIdentity') = 1
    and objectproperty(a.id, 'isTable') = 1

#4


0  

As expansion on @Blogbeard's answer

作为对@Blogbeard的回答的扩展

If you like pure query and not inbuilt functions

如果您喜欢纯查询,而不是内置函数。

select col_name(sys.all_objects.object_id, column_id) as id from sys.identity_columns 
join sys.all_objects on sys.identity_columns.object_id = sys.all_objects.object_id
where sys.all_objects.name = 'system_files'