Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

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
 
Share this answer
 
I got the solution:
SQL
SELECT IDENT_CURRENT('tblEmployee') AS LastIdentityValue
SELECT IDENT_SEED('tblEmployee') AS seed
SELECT IDENT_INCR('tblEmployee') AS Increment
 
Share this answer
 
Use the below code to fetch the schema detail from the data base

C#
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
 
Share this answer
 
v4

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900