zoukankan      html  css  js  c++  java
  • How change the identity increment of column ?

    Following statement can reset seed

    DBCC CHECKIDENT (tb,RESEED,5)

    but can't reset increment.

    how change the identity increment of column?

    I can't find the simple method,now I use Following sql script to change it.

    use tempdb
    go
    if exists(select * from sys.tables where name='tb')
    drop table tb
    go
    create table tb(id int identity(1,1primary key,name varchar(20))
    go
    insert into tb select 'a'
    go 5

    select * from tb

    create table tb_tmp(id int identity(1000,5primary key,name varchar(20))
    go
    set identity_insert tb_tmp on
    insert tb_tmp(id,name) select id,name from tb with(xlock,tablock)
    set identity_insert tb_tmp off
    drop table tb
    go
    exec sp_rename N'tb_tmp',N'tb'
    go
    insert into tb(name) select 'b'
    go 5
    select * from tb


    please tell me if you find bugs

    thanks for reading,

    nzperfect


    作者:nzperfect
    出处:http://www.cnblogs.com/nzperfect/
    引用或者转载本BLOG的文章请注明原作者和出处,并保留原文章中的版权信息。

  • 相关阅读:
    搭建LAMP及wordpress
    httpd2.4常用配置
    编译安装httpd 2.4
    https加密实现
    httpd常用配置
    源码编译安装bind
    安装mariadb二进制程序
    搭建互联网DNS构架
    搭建DNS服务
    主从及转发DNS搭建
  • 原文地址:https://www.cnblogs.com/nzperfect/p/1711937.html
Copyright © 2011-2022 走看看