identity in sql server 批量插入history
- The
@@identityfunction returns the last identity created in the same session. - The
scope_identity()function returns the last identity created in the same session and the same scope. - The
ident_current(name)returns the last identity created for a specific table or view in any session. - The
identity()function is not used to get an identity, it's used to create an identity in aselect...intoquery.
The session is the database connection. The scope is the current query or the current stored procedure.
A situation where the scope_identity() and the @@identity functions differ, is if you have a trigger on the table. If you have a query that inserts a record, causing the trigger to insert another record somewhere, the scope_identity() function will return the identity created by the query, while the @@identity function will return the identity created by the trigger.
So, normally you would use the scope_identity() function.
No, SCOPE_IDENTITY() only gives you the one, latest inserted IDENTITY value. But you could check out the OUTPUT clause of SQL Server ....
DECLARE @IdentityTable TABLE (SomeKeyValue INT, NewIdentity INT) INSERT INTO [MyTable]
OUTPUT Inserted.Keyvalue, Inserted.ID INTO @IdentityTable(SomeKeyValue, NewIdentity)
VALUES (''), (''), ('')
Once you've run your INSERT statement, the table variable will hold "some key value" (for you, to identify the row) and the newly inserted ID values for each row inserted. Now go crazy with this! :-)
其中Inserted是和Output有关系的
UPDATE OUTPUT into a variable
Because an update can affect multiple rows, it requires a table to store its results:
declare @ids table (id int);
UPDATE Foo
SET Bar = 1
OUTPUT INSERTED.Id INTO @ids
WHERE Baz = 2
If you're sure only one row will be affected, you can pull out the id like:
declare @id int
select top 1 @id = id
from @ids
identity in sql server 批量插入history的更多相关文章
- SQL Server 批量插入数据的两种方法
在SQL Server 中插入一条数据使用Insert语句,但是如果想要批量插入一堆数据的话,循环使用Insert不仅效率低,而且会导致SQL一系统性能问题.下面介绍 SQL Server支持的两种批 ...
- SQL Server 批量插入数据的两种方法(转)
此文原创自CSDN TJVictor专栏:http://blog.csdn.net/tjvictor/archive/2009/07/18/4360030.aspx 在SQL Server 中插入一条 ...
- 转:SQL Server 批量插入数据的两种方法
在SQL Server 中插入一条数据使用Insert语句,但是如果想要批量插入一堆数据的话,循环使用Insert不仅效率低,而且会导致SQL一系统性能问题.下面介绍SQL Server支持的两种批量 ...
- SQL Server 批量插入
使用场景 在项目中,涉及到数据库表变更时,可能会需要将一个或多个表中的数据迁移到另一个表中. 这时用sql去执行会很方便! sql语句 //SQL批量插入 create table #ttableNa ...
- SQL Server 批量插入数据方案 SqlBulkCopy 的简单封装,让批量插入更方便
一.Sql Server插入方案介绍 关于 SqlServer 批量插入的方式,有三种比较常用的插入方式,Insert.BatchInsert.SqlBulkCopy,下面我们对比以下三种方案的速度 ...
- SQL server 批量插入和更新数据
批量插入数据 insert into A表数据库名.[dbo].A(a,b,c) (select a,b,c from B表数据库名.[dbo].B) 批量更新数据 根据身份证第二位更新性别 upda ...
- SQL Server 批量插入数据的方法
运行下面的脚本,建立测试数据库和表. --Create DataBase create database BulkTestDB; go use BulkTestDB; go --Create Tabl ...
- SQL SERVER 批量插入记录
--create function insertData(@count as int,@tsn as bigint,@id as int) --as --begin SET IDENTITY_INSE ...
- SQL Server 批量插入数据
请看代码: 创建表值参数类型: 请看代码:
随机推荐
- 使用IDEA 搭建一个SpringBoot + Hibernate + Gradle
---恢复内容开始--- 打开IDEA创建一个新项目: 第一步: 第二步: 第三步: 最后一步: 如果下载的时候时间太久.可以找到build.gradle文件,添加以下代码.如下图 maven{ ur ...
- Activity生命周期(待整理)
1. 定义 有一些方法共同定义生命周期,如下图示:(图片来自于官网文档) 2. onStart()——在Activity即将对用户可见之前调用 (1)Activity启动动画.二维动画在onStart ...
- 八:前端---Vue下的国际化处理
1:首先安装 Vue-i8n npm install vue-i18n --save 注:-save-dev是指将包信息添加到devDependencies,表示你开发时依赖的包裹. -save是指将 ...
- Mongo连接远程数据库
mongo IP+Port CrabyterV5 首先这么操作是基于配置了环境变量的,可以参照http://www.cnblogs.com/daiyonghui/p/5209076.html mong ...
- QS之force(3)
Example in project - First force signals in certain time and then noforce signals after some time. # ...
- Embedded之Stack之三
Stack Overflow While stacks are generally large, they don't occupy all of memory. It is possible to ...
- 安卓代码迁移:Program "sh" not found in PATH
Description Resource Path Location Type Program "sh" not found in PATH 参考链 ...
- vue 上滑加载更多
移动端网页的上滑加载更多,其实就是滑动+分页的实现. <template> <div> <p class="footer-text">--{{f ...
- Day 17 time,datetime,random,os,sys,json,pickle
time模块 1.作用:打印时间,需要时间的地方,暂停程序的功能 时间戳形式 time.time() # 1560129555.4663873(python中从1970年开始计算过去了多少秒) 格式化 ...
- eas之Uuid和BOSUuid 区别
BOSUuid 加入了BOSType的概念,这个唯一码跟 BOSType有关,里面包含了BOSType的信息. 根据BOSType可以生产BOSUuid,同样,根据BOSUuid也可以找到BOSTyp ...