SQL SERVER 2008获取最后插入的值 [英] SQL SERVER 2008 GET LAST INSERTED VALUES
本文介绍了SQL SERVER 2008获取最后插入的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的桌子.
Ticket(id int auto_increment,name varchar(50));
在插入此表后,我想发送ID和名称到邮件. 我如何获得最后的插入值.
after inserting into this table i want send id and name to mail.. how can i get the last Inserted value.
帮助解决此问题...
help to solve this...
推荐答案
查看:具有该表的身份属性的表,我们可以获取最后插入的记录ID,就像这样
The table which is having Identity Property from that table we can get the last inserted record id will be like this
SELECT SCOPE_IDENTITY()
OR
但这不是一种安全的技术:
But this is not a safe technique:
SELECT MAX(Id) FROM Ticket
OR
这也不是一种安全的技术:
This is also not a safe technique:
SELECT TOP 1 Id FROM Ticket ORDER BY Id DESC
这篇关于SQL SERVER 2008获取最后插入的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文