SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 SQL Server Administration (2000)
 Columns
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

danasegarane76
Posting Yak Master

India
240 Posts

Posted - 05/30/2007 :  03:31:18  Show Profile  Send danasegarane76 an ICQ Message  Reply with Quote
Dear All,
How can I get the column names and identity value for a particular table using one query

Dana

harsh_athalye
Flowing Fount of Yak Knowledge

India
5509 Posts

Posted - 05/30/2007 :  03:36:19  Show Profile  Visit harsh_athalye's Homepage  Click to see harsh_athalye's MSN Messenger address  Send harsh_athalye a Yahoo! Message  Reply with Quote
select column_name, ident_incr('table_name')
from information_schema.columns
where table_name = 'table_name' and columnproperty(object_id(table_name), column_name, 'IsIdentity')=1


Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

danasegarane76
Posting Yak Master

India
240 Posts

Posted - 05/30/2007 :  05:27:23  Show Profile  Send danasegarane76 an ICQ Message  Reply with Quote
Thanks Harsh,
But i need to list the column names ,not the count .Sorry if i am disturbing too much

Dana
Go to Top of Page

AndyB13
Aged Yak Warrior

United Kingdom
583 Posts

Posted - 05/30/2007 :  06:52:39  Show Profile  Reply with Quote
The sql Harsh provided didnt provide the count. ident_incr - is the incremental value

Try this - this is not much different to what Harsh provided except it shows all columns

USE Northwind
GO

SELECT 	COLUMN_NAME, 
	COLUMNPROPERTY(object_id('Orders'),COLUMN_NAME,'IsIdentity') AS IsIdentity,
	IDENT_INCR('ORDERS') AS INCREMENT_VALUE,
	IDENT_CURRENT('ORDERS') AS CURRENT_VALUE
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'Orders'  


Andy

Beauty is in the eyes of the beerholder
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000