SQL:如何获取我刚刚插入的值的 id? [英] SQL: How to get the id of values I just INSERTed?

查看:23
本文介绍了SQL:如何获取我刚刚插入的值的 id?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在表格中插入了一些值.有一列的值是自动生成的.在我的代码的下一个语句中,我想检索这个值.

I inserted some values into a table. There is a column whose value is auto-generated. In the next statement of my code, I want to retrieve this value.

你能告诉我正确的方法吗?

Can you tell me how to do it the right way?

推荐答案

@@IDENTITY 不是范围安全的,如果您在原始表上有插入触发器,它将从另一个表中取回 id表,始终使用 SCOPE_IDENTITY()

@@IDENTITY is not scope safe and will get you back the id from another table if you have an insert trigger on the original table, always use SCOPE_IDENTITY()

这篇关于SQL:如何获取我刚刚插入的值的 id?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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