如何获取插入数据库中的最后一个值 [英] How to get last value inserted in the data base
本文介绍了如何获取插入数据库中的最后一个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在将类似于1ob-003-ee的卷号插入数据库列,我想知道数据库中插入的最后一个值,这样我可以通过将003加到004来插入更多数据,我该怎么做.任何人都可以向我查询.
我很困惑,应该使用@identity添加数据还是其他一些东西,请帮帮我.
I am inserting a roll number similar to 1ob-003-ee to a database column i want to know the last value inserted in the data base so that i can insert more data by adding 003 to 004 how can i do this . Can anybody provide me the query .
I am confused that should i use @identity to add data or some thing else please help me.
推荐答案
DECLARE @ID INT
INSERT INTO TableName (Columns1, Column2)
VALUES(Value1, Value2)
SET @ID = @@IDENTITY
-查看最后插入的身份值
选择@ID AS [身份]
身份 [
--View Last inserted identity Value
SELECT @ID AS [Identity]
IDENTITY[^]
这篇关于如何获取插入数据库中的最后一个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文