Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

Browse by Tags · View All
sql_server 217
t-sql 211
tsql 116
sqlserver 96
BRH 78
#SQLServer 66
#TSQL 56
SQL Server 34
function 11
SSMS 9

Archive · View All
August 2007 17
August 2010 8
June 2012 7
June 2011 7
November 2007 7
August 2012 6
May 2012 6
November 2011 6
August 2011 6
October 2011 6

Madhivanan's TSQL Blog

SQL Server - Identifying identity columns using TSQL

Aug 16 2010 3:06AM by Madhivanan   

One of my friends asked me if it is possible to identify the tables with identiy columns as he wanted to run dbcc checkident command to all the tables of the database.There are actually many ways to identify identity columns from a table.The following three methods will list out the table names and the identity column name (if available)

Method 1 : Use columnproperty function

select 
	table_name,column_name 
from 
	information_schema.columns
where 
	columnproperty(object_id(table_name),column_name,'isidentity')=1
order by table_name

Method 2 : Use sys.all_columns view

select 
	object_name(ac.object_id),so.name 
from 
	sys.all_columns as ac inner join sys.objects as so
	on object_name(ac.object_id)=so.name
where 
	is_identity=1  and so.type='u'

You can also simply use

select 
	object_name(object_id),name 
from 
	sys.all_columns 
where 
	is_identity=1  and objectproperty(object_id,'isusertable')=1

Method 3 : Use sys.identity_columns view

select 
	object_name(id.object_id),so.name 
from 
	sys.identity_columns as id inner join sys.objects as so
	on object_name(id.object_id)=so.name
where 
	so.type='u'

and simplified code is

select 
	object_name(object_id),name 
from 
	sys.identity_columns 
where 
	objectproperty(object_id,'isusertable')=1

Tags: t-sql, sql_server, tsql, BRH, #TSQL, #SQLServer, identity, columnproperty,


Madhivanan
3 · 39% · 12441
1
 
0
Lifesaver
 
0
Refreshed
 
0
Learned
 
0
Incorrect



Submit

Your Comment


Sign Up or Login to post a comment.

"SQL Server - Identifying identity columns using TSQL" rated 5 out of 5 by 1 readers
SQL Server - Identifying identity columns using TSQL , 5.0 out of 5 based on 1 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]