Solved

Retreiving Identity attributes

Posted on 2001-09-05
4
249 Views
Last Modified: 2013-12-25
I need to retreive a field's Identity attributes (Identity, Seed and Increment). All this for SQL 7 / 2000 databases and using ADO, ADOX or pure SQL.

Any ideas?
0
Comment
Question by:Éric Moreau
  • 2
  • 2
4 Comments
 
LVL 39

Expert Comment

by:appari
Comment Utility

SELECT TABLE_NAME, IDENT_INCR(TABLE_NAME) AS IDENT_INCR, IDENT_SEED(TABLE_NAME) as IDENT_SEED
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME ='employees'

replace with your table name.


0
 
LVL 69

Author Comment

by:Éric Moreau
Comment Utility
This is working great but ... how can I know which field has the identity property set to Yes?
0
 
LVL 39

Accepted Solution

by:
appari earned 200 total points
Comment Utility
SELECT name
from syscolumns
where id =OBJECT_ID('employees')
and COLUMNPROPERTY( OBJECT_ID('employees'),name,'IsIdentity')=1

0
 
LVL 69

Author Comment

by:Éric Moreau
Comment Utility
Great!

I joined all that togheter. Is is the final result:

SELECT SO.Name AS TableName, SC.Name AS FieldName,
     Ident_Seed(Info.Table_Name) AS IdSeed,
     Ident_Incr(Info.Table_Name) AS IdIncrement,
     Ident_Current(Info.Table_Name) AS IdCurrent
FROM SysObjects AS SO
INNER JOIN SysColumns AS SC
ON SO.Id = SC.Id
INNER JOIN information_schema.Tables AS Info
ON Info.Table_Name = SO.Name
WHERE SO.Name = 'Analyst'
AND ColumnProperty(OBJECT_ID('Analyst'), SC.Name, 'IsIdentity') = 1
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now