How change the identity increment of column?

Source: Internet
Author: User

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 , 1 ) Primary   Key , Name Varchar ( 20 ))
Go
Insert   Into TB Select   ' A '
Go   5

Select * FromTB

Create   Table Tb_tmp (ID Int   Identity ( 1000 , 5 ) Primary   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

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.