如何获取Sql Server表中列的身份规范详细信息? [英] How to Fetch Identity specification details of Column in Sql Server table?

查看:85
本文介绍了如何获取Sql Server表中列的身份规范详细信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获取sql server中表列的身份规范详细信息(身份增量和身份种子).有什么方法可以在存储过程中或使用asp.net c#代码获取指定的详细信息?

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?

推荐答案

使用以下代码从数据库获取架构详细信息

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


我找到了解决方法:
I got the solution:
SELECT IDENT_CURRENT('tblEmployee') AS LastIdentityValue
SELECT IDENT_SEED('tblEmployee') AS seed
SELECT IDENT_INCR('tblEmployee') AS Increment




请尝试这个

从sys.identity_columns中选择is_identity,seed_value,increment_value,其中name ="[colum name]"


如果这不是您的解决方案,请进一步说明


谢谢

世居
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


这篇关于如何获取Sql Server表中列的身份规范详细信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆