Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
I want to fetch the indentity specification details(identity increment and identity seed) of a column of a table in sql server. Is there any way to fetch the specified details in stored procedure or using asp.net c# code?
Posted 7-Oct-12 21:13pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Use the below code to fetch the schema detail from the data base
 
         string conString = //your connection sting
         string query = "select * from tableName"; 
         SqlConnection con = new SqlConnection(conString);
 
         try 
         {
            con.Open();
            SqlCommand cmd = new SqlCommand(query, con);
            SqlDataReader reader = cmd.ExecuteReader();
            //Below schema obj contain the schema of the table 
            DataTable schema = reader.GetSchemaTable();
            //Schema obj has all the details that you want 
            reader.Close();
         } 
         catch(Exception e) 
         {
            Console.WriteLine("Error Occurred: " + e);
         } 
         finally 
         {
            conn.Close();
         }
 
Hope this will help you
  Permalink  
v4
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

I got the solution:
SELECT IDENT_CURRENT('tblEmployee') AS LastIdentityValue
SELECT IDENT_SEED('tblEmployee') AS seed
SELECT IDENT_INCR('tblEmployee') AS Increment
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Hi
 
pls try this
 
select is_identity,seed_value,increment_value from sys.identity_columns where name = '[colum name]'
 

if this is not your solution please give some more clarification
 

Thanks
 
Shiju
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 626
1 OriginalGriff 311
2 Maciej Los 210
3 Mehdi Gholam 145
4 PIEBALDconsult 140
0 Sergey Alexandrovich Kryukov 11,384
1 OriginalGriff 5,783
2 Maciej Los 5,684
3 CPallini 3,879
4 BillWoodruff 3,584


Advertise | Privacy | Mobile
Web03 | 2.8.141030.1 | Last Updated 8 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100