前言:今天在群里看到有人在问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)的更多相关文章

  1. 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 ...

  2. sql server identity限制

    identity属性是依赖于表的,它不是一种独立的序列机制,不能随意使用它生成新值. 标识值是在insert语句执行时生成的,不是在执行之前生成的. identity属性是以异步的方式分配标识值.这意 ...

  3. SQL Server identity种子

    背景: 用identity修饰列可以使它自动增长 例了: create table T(ID int not null identity(1,1),      Data nvarchar(32)); ...

  4. SQL SERVER ->> IDENTITY相关函数

    IDENTITY函数 -- 只能用在SELECT INTO语句中,用于在插入数据的时候模拟IDENTITY属性的作用生成自增长值. ,) AS ID_Num INTO NewTable FROM Ol ...

  5. ASP.NET MVC Identity 使用自己的SQL Server数据库

    之前在网上看到的一篇后来找不到了,现在自己记录一下. 1.在web.config中添加一个数据库连接. <add name="dataContext" connectionS ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. SQL Server Column Store Indeses

    SQL Server Column Store Indeses SQL Server Column Store Indeses 1. 概述 2. 索引存储 2.1 列式索引存储 2.2 数据编码和压缩 ...

随机推荐

  1. iOS之判断字符串是否为空字符的方法

    -  (BOOL) isBlankString:(NSString *)string { if (string == nil || string == NULL) { return YES; } if ...

  2. 一些Titanium学习的地方

    利用titanium兑现外汇兑换计算的ios代码   http://rensanning.iteye.com/blog/1325011 Titanium兑现相关的报表功能   http://www.s ...

  3. 快速上手Unity原生Json库

    现在新版的Unity(印象中是从5.3开始)已经提供了原生的Json库,以前一直使用LitJson,研究了一下Unity用的JsonUtility工具类的使用,发现使用还挺方便的,所以打算把项目中的J ...

  4. (八)map,filter,flatMap算子-Java&Python版Spark

    map,filter,flatMap算子 视频教程: 1.优酷 2.YouTube 1.map map是将源JavaRDD的一个一个元素的传入call方法,并经过算法后一个一个的返回从而生成一个新的J ...

  5. 跳入linux的第一个坑-因为安装Ubuntu导致的硬盘被误格的恢复.(记TestDisk使用记录)

    不看废话,直接跳到操作说明 前几日心血来潮想把家中的旧笔记本换成Linux操作系统,算是在业余生活中正式投入Linux的怀抱.说干就干,发行版选择了Ubuntu,下载了Ubuntu16.04的ISO, ...

  6. vi(vim)键盘图及其基本命令

    进入vi vi filename                打开或新建文件,并将光标置于第一行首 vi +n filename           打开文件,并将光标置于第 n行首 vi + fi ...

  7. 由Photoshop高反差保留算法原理联想到的一些图像增强算法。

    关于高反差保留的用处说明呢,从百度里复制了一段文字,我觉得写得蛮好的: 高反差保留就是保留图像的高反差部分,再说得真白些,就是保留图像上像素与周围反差比较大的部分,其它的部分都变为灰色.拿一个人物照片 ...

  8. php 7.0 新特性

    php 7 主题是性能优化  SEO 之前版本:开发效率快,语言本身性能差 普通的php网站:IO密集型,瓶颈在mysql上,体现不出来php的性能劣势,在密集计算方面比C,C++,JAVA差几十倍甚 ...

  9. [LeetCode] Find Median from Data Stream 找出数据流的中位数

    Median is the middle value in an ordered integer list. If the size of the list is even, there is no ...

  10. [LeetCode] Copy List with Random Pointer 拷贝带有随机指针的链表

    A linked list is given such that each node contains an additional random pointer which could point t ...