前言:今天在群里看到有人在问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. InfoPath错误,此文档库已被重命名或删除

    在使用InfoPath发布表单,发布到SharePoint服务器报错,如下介绍: 环境:Windows 2012 DateCenter + Sql 2012 + SharePoint 2013 + O ...

  2. [转]通过Visual Studio为Linux编写C++代码

    Build 2016大会上Microsoft首次公布的Visual Studio 2015扩展提供了在VS2015中编写C++代码,随后通过Linux/UNIX计算机进行编译和执行的能力.这种想法非常 ...

  3. Oracle 外网访问

    环境:centos7+oracle 11gr2 公网:固定IP 症状:1521端口正常,netmanager配置测试正常,plsql连接提示ORA-12514: TNS:listener does n ...

  4. String构造器中originalValue.length>size 发生的情况

    最近在看Jdk6中String的源码的时候发现String的有个这样的构造方法,源代码内容如下: public String(String original) { int size = origina ...

  5. web安全相关知识

    xss攻击入门 XSS攻击及防御 XSS的原理分析与解剖 浅谈CSRF攻击方式 利用HTTP-only Cookie缓解XSS之痛 SERVLET 2.5为COOKIE配置HTTPONLY属性 coo ...

  6. 收集几个不错的最新win10系统64位和32位系统Ghost版下载

    系统来自转载:系统妈 ◆ 版本特点 该版本安装后可利用微软公开的Windows10 KMS密钥激活,且右小角无版本水印. KMS客户端密钥:NPPR9-FWDCX-D2C8J-H872K-2YT43, ...

  7. monkeyrunner之控件ID不存在或重复

    我们在用monkeyrunner进行Android自动化时,通过获取坐标点或控件ID进行一系列操作.由于使用坐标点时,屏幕分辨率一旦更改,则代码中用到坐标的地方都要修改,这样导致代码的复用率较低.因此 ...

  8. 记一次与a标签相遇的小事

    最近做的一个项目,按钮使用的是a标签做的,样子还不错.不过正是这个a标签把我坑死了,有一个场景是点击a标签去调后台服务,为了防止用户频繁点击按钮提交,在去请求后台服务的时候肯定要先把按钮的事件给禁止掉 ...

  9. NHibernate之映射文件配置说明

    NHibernate之映射文件配置说明 1. hibernate-mapping 这个元素包括以下可选的属性.schema属性,指明了这个映射所引用的表所在的schema名称.假若指定了这个属性, 表 ...

  10. Subsets II

    Given a collection of integers that might contain duplicates, nums, return all possible subsets. Not ...