是有可能在表中插入数据之前,以获得新的值的ID(标识)? [英] Is is possible to get new values for Id (IDENTITY) before inserting data in a table?

查看:150
本文介绍了是有可能在表中插入数据之前,以获得新的值的ID(标识)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

时有可能在一个表中插入数据之前,以获得新的值ID(身份)

Is is possible to get new values for Id (IDENTITY) before inserting data in a table ?

时也可能写出这样的事情:

Is is possible to write something like that :

INSERT INTO Table1
SELECT *GET_NEW_IDENTITY*, Field1, Field2 FROM Table2

我需要标识的值,因为我想在表1中插入数据,刚过,<其中有连接到一个外键的另一个表strong>插入数据表1 (带编号)

I need the values of Id because I want to insert data in Table1 and, just after, insert data in another table which has a foreign key linked to Table1 (with Id)

推荐答案

IDENT_CURRENT 。返回指定表或视图生成的最后一个标识值。生成的最后一个标识值可以为任何会话和范围。

IDENT_CURRENT. Returns the last identity value generated for a specified table or view. The last identity value generated can be for any session and any scope.

SCOPE_IDENTITY 。返回插入到相同范围的标识列的最后一个标识值。作用域是一个模块:一个存储过程,触发器,函数或批处理

SCOPE_IDENTITY. Returns the last identity value inserted into an identity column in the same scope. A scope is a module: a stored procedure, trigger, function, or batch.

输出。返回从信息,或基于表达式,受一个INSERT每行,UPDATE,DELETE或MERGE语句。 [...] OUTPUT子句可检索身份的插入或更新操作后的值或计算列有用的。

OUTPUT. Returns information from, or expressions based on, each row affected by an INSERT, UPDATE, DELETE, or MERGE statement. [...] The OUTPUT clause may be useful to retrieve the value of identity or computed columns after an INSERT or UPDATE operation.

这篇关于是有可能在表中插入数据之前,以获得新的值的ID(标识)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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