Reset Identity Column Value in SQL Server (Identity Reset)
前言:今天在群里看到有人在问SQL Server自增值重置问题(sqlserver identiy column value reset )
闲话少说,直接上代码:
正文:
--create table
--create test table
if not exists(select * from sysobjects where name = 'Test_1')
begin
create table Test_1 (ID int identity(1,1) primary key,Name nvarchar(128),CreateDate datetime);
end
else
begin
drop table Test_1;
create table Test_1 (ID int identity(1,1) primary key,Name nvarchar(128),CreateDate datetime);
end
go
--insert test data into table
declare @ID int;
select @ID = 1001;
while(@ID < 1101)
begin
insert into Test_1 values('Name'+ CONVERT(nvarchar(128),@ID),GETDATE());
select @ID = @ID + 1;
end
--select data from test table
select * from Test_1;

--delete data
--delete data from test table
delete from Test_1;
--reset identity
DBCC CHECKIDENT (Test_1, RESEED,0)
再次执行插入语句后查看结果
--insert data into test table
declare @ID int;
select @ID = 1001;
while(@ID < 1101)
begin
insert into Test_1 values('NameS'+ CONVERT(nvarchar(128),@ID),GETDATE());--PS:第二次Name值有改动
select @ID = @ID + 1;
end
select * from Test_1;

结束语:DBCC CHECKIDENT (Test_1, RESEED,0) -- reset identity value
Reset Identity Column Value in SQL Server (Identity Reset)的更多相关文章
- Invalid column name on sql server update after column create
问题:新建一个测试表xx as code into xx select * from xx 给这个表添加一个列val, val列不允许为空,将表中已有的数据val值更新为1 alter table x ...
- sql server identity限制
identity属性是依赖于表的,它不是一种独立的序列机制,不能随意使用它生成新值. 标识值是在insert语句执行时生成的,不是在执行之前生成的. identity属性是以异步的方式分配标识值.这意 ...
- SQL Server identity种子
背景: 用identity修饰列可以使它自动增长 例了: create table T(ID int not null identity(1,1), Data nvarchar(32)); ...
- SQL SERVER ->> IDENTITY相关函数
IDENTITY函数 -- 只能用在SELECT INTO语句中,用于在插入数据的时候模拟IDENTITY属性的作用生成自增长值. ,) AS ID_Num INTO NewTable FROM Ol ...
- ASP.NET MVC Identity 使用自己的SQL Server数据库
之前在网上看到的一篇后来找不到了,现在自己记录一下. 1.在web.config中添加一个数据库连接. <add name="dataContext" connectionS ...
- Part 4 Identity Column in SQL Server
Identity Column in SQL Server If a column is marked as an identity column, then the values for this ...
- Microsoft SQL Server Version List [sqlserver 7.0-------sql server 2016]
http://sqlserverbuilds.blogspot.jp/ What version of SQL Server do I have? This unofficial build ch ...
- Microsoft SQL Server Version List(SQL Server 版本)
原帖地址 What version of SQL Server do I have? This unofficial build chart lists all of the known Servic ...
- SQL Server Column Store Indeses
SQL Server Column Store Indeses SQL Server Column Store Indeses 1. 概述 2. 索引存储 2.1 列式索引存储 2.2 数据编码和压缩 ...
随机推荐
- iOS - NSMutableAttributedString富文本的实现
NSMutableAttributedString继承于NSAttributedString(带属性的字符串)能够简单快速实现富文本的效果;不多说直接上效果图和代码,通俗易懂: (一)效果图: (二) ...
- 跳转时候提示Attempt to present on while a presentation is in progress
出现这种情况,例如:我在获取相册图片后,直接present到另一个页面,但是上一个页面可能还未dismiss,所以,要在获取相册图片的dismiss方法的complete的block里面写获取图片及跳 ...
- http转https 和 微信小程序设置了合法请求域名,小程序一直提示不在合法域名列别中
hotapp 有免费的https proxy ,可以免费代理请求任何http或者https服务,只要设置好合法域名为https://wxapi.hotapp.cn , 就可以请求网址如请求小程序联盟的 ...
- SQL优化技术分析-4:其他
ORACLE的提示功能是比较强的功能,也是比较复杂的应用,并且提示只是给ORACLE执行的一个建议,有时如果 出于成本方面的考虑ORACLE也可能不会按提示进行.根据实践应用,一般不建议开发人员应用O ...
- DBMS_NETWORK_ACL_ADMIN
DBMS_NETWORK_ACL_ADMIN学习 转载 http://blog.sina.com.cn/s/blog_4f925fc30102e2se.html 标签: oracle it 分类: 数 ...
- Scala变量(三)
变量是一种使用方便的占位符,用于引用计算机内存地址,变量创建后会占用一定的内存空间. 基于变量的数据类型,操作系统会进行内存分配并且决定什么将被储存在保留内存中.因此,通过给变量分配不同的数据类型,你 ...
- Linux基础练习题(三)
1.显示当前系统上root.fedora或user1用户的默认shell: [root@www ~]# egrep "^(root|fedora|user1)" /etc/pass ...
- PHP核心技术与最佳实践——全局浏览
难得买到并喜欢一本好书,‘PHP核心技术与最佳实践’. 几天时间,先看了个大概,总结一下整体是什么样子的,怎么看怎么学. 1.总共14章: 2.第1.2章讲PHP的OOP: 其中第一章侧重于PHP的O ...
- BZOJ 3289: Mato的文件管理[莫队算法 树状数组]
3289: Mato的文件管理 Time Limit: 40 Sec Memory Limit: 128 MBSubmit: 2399 Solved: 988[Submit][Status][Di ...
- python中的迭代、生成器等等
本人对编程语言实在是一窍不通啊...今天看了廖雪峰老师的关于迭代,迭代器,生成器,递归等等,word天,这都什么跟什么啊... 1.关于迭代 如果给定一个list或tuple,我们可以通过for循环来 ...