Wednesday, March 28, 2012

Information schema

How can I find out if a specific column is an Identity column or which
column in a specific table is the Identity column?
Thank you.Lookup the metadata function COLUMNPROPERTY in SQL Server Books Online. It
has an argument which takes the value IsIdentity that can be used for such
requirements.
Anith|||Try,
use northwind
go
select
table_schema,
table_name,
column_name,
ident_seed(table_schema + '.' + quotename(table_name)) as col_ident_seed,
ident_incr(table_schema + '.' + quotename(table_name)) as col_ident_incr,
ident_current(table_schema + '.' + quotename(table_name)) as
col_ident_current
from
information_schema.columns
where
objectproperty(object_id(table_schema + '.' + quotename(table_name)),
'IsUserTable') = 1
and objectproperty(object_id(table_schema + '.' + quotename(table_name)),
'IsMSShipped') = 0
and columnproperty(object_id(table_schema + '.' + quotename(table_name)),
column_name, 'IsIdentity') = 1
order by
table_schema,
table_name,
ordinal_position
go
AMB
"Vik" wrote:

> How can I find out if a specific column is an Identity column or which
> column in a specific table is the Identity column?
> Thank you.
>
>

No comments:

Post a Comment