SQL-插入行并返回主键 [英] SQL - Inserting a row and returning primary key

查看:71
本文介绍了SQL-插入行并返回主键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小巧的问题.说,我在存在主键的表中插入了一些数据行.如何选择"刚刚插入的第一行的主键?

I have a little witty problem. Say, I inserted a row with some data in a table where a primary key is present. How would one "SELECT" the primary key of the row one just inserted?

我应该更具体一些,并提到我目前 使用SQLite.

I should have been more specific and mentioned that I'm currently using SQLite.

推荐答案

对于MS SQL Server:

For MS SQL Server:

SCOPE_IDENTITY() 将返回您在当前范围内最后生成的标识值:

SCOPE_IDENTITY() will return you the last generated identity value within your current scope:

SELECT SCOPE_IDENTITY() AS NewID

这篇关于SQL-插入行并返回主键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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