SET IDENTITY_INSERT <Table Name> ON/OFF 转载
This command is from SQL Server. This command is to enable the users to set their own value for IDENTITY Column in case they want to. This has been the very useful for us. We use it in MERGE and RDA when we send the client side inserts to server where we want to make sure to insert the row on server with the IDENTITY value generated by client.
Today in SQL Server CE (SSCE), we have no way to set our own value for IDENTITY column. Now there is a strong need for this feature in SQL Server Compact Edition. Here are some more details:
SQL Server CE 2.0 supported setting the IDENTITY Column value and the apps migrated to SQL Mobile 3.0 have severely broken on this front. Ex: Data Port Wizard from prime works
What has been given as a work around to customer right now is given below:
We can change the seed and step by “ALTER TABLE ALTER COLUMN”. So, before doing an INSERT into SQL Server Compact database, one has to execute this “ALTER TABLE ALTER COLUMN” command to set the seed such a way that the next INSERT-ed row gets the value required. But this is really a pain, because:
- ALTER TABLE ALTER COLUMN is a DDL. Hence, the cursor needs to be closed and opened again.
- ALTER TABLE ALTER COLUMN is required for every INSERT. Which means, an INSERT becomes:
a) Open Cursor b) ALTER TABLE c) Close Cursor d) Open Cursor e) INSERT Row f) Close Cursor
It is much like another session variable similar to “SET SHOWPLAN_XML ON”. We skip identity checks, when this session variable for a table is ON.
USAGE-HOW-TO:
CREATE TABLE testIdentity (id int IDENTITY (1,1), name nvarchar(100));
INSERT INTO testIdentity(name) VALUES ('name1'); è Row will be (1, name1)
INSERT INTO testIdentity(name) VALUES ('name2'); è Row will be (2, name2)
SET IDENTITY_INSERT testIdentity ON;
INSERT INTO testIdentity (id, name) VALUES (10, 'name10'); è Row will be (10, name10)
INSERT INTO testIdentity (id, name) VALUES (20, 'name20'); è Row will be (20, name20)
SET IDENTITY_INSERT testIdentity OFF;
INSERT INTO testIdentity(name) VALUES ('name??'); è Row will be (3, name??)
Here you can observe that SQL Server automatically uses 21 for the last row. That is, SQL Server just leaves holes. However, we chose to not leave holes. Hence, in SQL Server Compact the last row would get value ‘3’ for IDENTITY column. This is basically for the reason that, when we are a merge replicated database we have a certain slot allocated to a subscriber and this range/slot is better managed by merge. If we chose to behave as SQL Server here, IDENTITY_INSERT updates the AUTOINC_NEXT which MAY fall out of our allocated range which would pose a serious issue. However, user can always get SQL Server behavior by “ALTER TABLE <Table Name> ALTER COLUMN <Column Name> <Datatype> IDENTITY(<New Seed>, <New Step>)”.
Thanks,
Laxmi Narsimha Rao ORUGANTI
SET IDENTITY_INSERT <Table Name> ON/OFF 转载的更多相关文章
- DBCC CHECKIDENT 和SET IDENTITY_INSERT table OFF
TRUNCATE TABLE [DBO].TRACKING_CODE_BASE_Jasmine DELETE FROM TRACKING_CODE_BASE_Jasmine 有同一张表,一次用trun ...
- kernel nf_conntrack: table full, dropping packet[转载]
http://blog.yorkgu.me/2012/02/09/kernel-nf_conntrack-table-full-dropping-packet/ 综合:ip_conntrack就是li ...
- WPF中,Grid与Table的区别(英文)-转载
原文地址:http://blog.csdn.net/johnsuna/article/details/1742799 How is Grid Different from Table?Table an ...
- EF架构~为BulkInsert引入SET IDENTITY_INSERT ON功能
回到目录 在设计表结构时,我们通常将不是很在乎表现的主键设计成自增长的,大数据量用bigint,一般地用int就可以了,int就是C#里的Int32,它最大可以存储到2147483647,21亿,基本 ...
- 在线重定义(Rdefine Table online)
二. 概念理解 在线重定义用于对表的逻辑或者物理结构的修改,而且在修改时不影响表的可用性与传统方式相比.当一个表被重定义时,会被锁定为exclusive mode很短一段时间,这段时间的 ...
- html表格导出Excel的一点经验心得(转载)
最近在做统计功能,要求统计结果(表格)既能查看(BS系统,在浏览器查看),又能输出为excel文件.对于输出excel文件,在网上找到n种方案,因为还需查看,最终选择了统计结果输出为table,查看时 ...
- 把IDENTITY_INSERT 设置为 ON ,还不能插入数据问题
IDENTITY_INSERT 为 ON 时 , 必须把需要插入的列名列出来 不然报错 正确例子: SET IDENTITY_INSERT table(表名) ONinsert into table ...
- javascript实现汉诺塔动画效果
javascript实现汉诺塔动画效果 当初以为不用html5也很简单,踩了javascript单线程的大坑后终于做出来了,没事可以研究下,对理解javascript的执行过程还是很有帮助的,代码很烂 ...
- Identity标识列
SQL Server中,经常会用到Identity标识列,这种自增长的字段操作起来的确是比较方便.但它有时还会带来一些麻烦. 示例一 :当表中被删除了某些数据的时候,自增长列的编号就不再是一个连线的数 ...
随机推荐
- Android Broadcast Security(转)
原文地址:http://drops.wooyun.org/tips/4393 0x00 科普 Broadcast Recevier 广播接收器是一个专注于接收广播通知信息,并做出对应处理的组件.很多广 ...
- VMware8安装MacOS 10.8
前一篇博客,介绍了如何利用VMware安装MacOS系统,虽然可以安装成功,但也有不友好的地方,如: 1)MacOS系统文件需要是ISO格式,不是原生的dmg格式: 2)每次开机都需要借助HJMac工 ...
- VMware虚拟机怎么从U盘启动
VMware虚拟机怎么从U盘启动 发布时间:2016-01-12 18:50发布者:系统城-xtcjh浏览数:41951 VMware Workstation虚拟机可以安装各种操作系统,很多用户就想在 ...
- python 机器学习中的数据处理学习记录
在机器学习中,选择合适的算法固然重要,但是数据的处理也同样重要.通过对数据的处理,能提高计算效率,提高预测识别精确度等等 以下记录下一些数据处理的方法 一.处理缺失值 对于数据集中有缺失值的,粗暴的方 ...
- HTML5基础知识汇总_(2)自己定义属性及表单新特性
自己定义属性data-* 说起这个属性,事实上如今非经常见了;怎么说呢,由于在一些框架都能看到他的身影!!! 比方Jquery mobile,里面非常频繁的使用了这个属性; 这个属性是哪里来的-.当然 ...
- linux经常使用文字处理命令总结
linux grep命令 作用 Linux系统中grep命令是一种强大的文本搜索工具,它能使用正則表達式搜索文本,并把匹 配的行打印出来.grep全称是Global Regular Expressio ...
- 十大迷你iPhone天气应用
来源:GBin1.com 天气特别是指大气情况这样的状态通常包括温度,风,云,湿度和降雨等.上述情况下的天气状况很大程度影响了我们的生活和每天的日常活动.天气可能会经常出乎意料,所以往往希望能够准确提 ...
- 正则表达式匹配a标签或div标签
这里以a标签为例 a标签的href var a='<P><A href=\'~abc/ccg/ab.jpg\' width="3">文字</A> ...
- 算法笔记_100:蓝桥杯练习 算法提高 三个整数的排序(Java)
目录 1 问题描述 2 解决方案 1 问题描述 问题描述 输入三个数,比较其大小,并从大到小输出. 输入格式 一行三个整数. 输出格式 一行三个整数,从大到小排序. 样例输入 33 88 77 样 ...
- PyQt4的一些问题汇总
(1)PyQt4获取中文路径名字乱码问题 网址可以参见:http://permalink.gmane.org/gmane.comp.python.chinese/9916 处理方式的代码可以参考如下 ...