如何获得ROWINDEX以及如何使用rowindex通过唯一key(id)在表中插入数据库. [英] How can get ROWINDEX and how can use of rowindex insert database in table by unique key(id) .

查看:54
本文介绍了如何获得ROWINDEX以及如何使用rowindex通过唯一key(id)在表中插入数据库.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尊敬的先生/女士


我是Shailendra Singh,是.Net的新手.如何获取ROWINDEX以及如何在表中使用rowindex插入数据库.我想通过唯一键(id)从数据库表中检索rowindex.任何人都可以帮助我.






在此先感谢

Dear sir/Mam


I am Shailendra Singh and I am new to .Net .How can get ROWINDEX and how can use of rowindex insert database in table.I want to retrive rowindex from database table by unique key(id).Any one help me.






Thanks In Advance

推荐答案

在存储过程中使用select @@ identity

然后您将获得最后插入的行索引...
use select @@identity in your stored procedure

and you will get the last inserted row index ...


使用最大功能从相应表中获取最大ID
声明@rowIndex int
从TableName中选择@rowIndex = max(columnName)

在插入查询中使用@rowIndex
通过这种方式插入到tableName(columnName)值(@rowIndex)
Get the maximum ID using max fuction from respective table
declare @rowIndex int
Select @rowIndex = max(columnName) from TableName

Use the @rowIndex in your insert query
Insert into tableName (columnName) values (@rowIndex)


中,您可以检索特定表的最后一个rowindex

by using this way, u can retrive last rowindex of perticular table

if(@CMD = 'INSERT')
BEGIN
INSERT INTO table_name(column_name) 
    VALUES(Add_your_value)

SET @_RGP = SCOPE_IDENTITY()

SELECT @_RGP AS last_rowindex

END


这篇关于如何获得ROWINDEX以及如何使用rowindex通过唯一key(id)在表中插入数据库.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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