datetime century date into pad dynamic cursor money percent sp job isnumeric isdate over update
SQLUSA.com
SQL 2008 GRAND SLAM ON 49 CD
FREE TRIAL  CLICK HERE TO ORDER  SEARCH
SQL Server Training SQL 2005 Scripts SQL 2008 Articles
SQL JOBS News Format Developer
How to reseed the identity value on a table?

Execute the following Microsoft SQL Server T-SQL scripts to demonstrate how to change IDENTITY sequence:

-- CHECKIDENT method for reseeding identity column - QUICK SYNTAX

DBCC CHECKIDENT('dbo.Customer', RESEED, 100 )

------------

 

-- Check current seed value

DBCC CHECKIDENT('Production.Product', NORESEED);

-- Checking identity information: current identity value '999', ...

------------

 

-- SQL INSERT basic syntax - INSERT VALUES - INSERT SELECT

USE AdventureWorks2008;

CREATE TABLE ProductAlpha (

  ProductID INT IDENTITY(1,1) PRIMARY KEY,

  ProductName varchar(64) UNIQUE,

  Price money not null CHECK   (Price > 0),

  ModifiedDate date default (getdate()));

 

INSERT ProductAlpha (ProductName, Price) VALUES

('BMW 330i automatic', $50000),

('BMW 330i manual', $49000),

('BMW 528i automatic', $60000)

 

INSERT ProductAlpha (ProductName, Price)

SELECT 'BMW 128i manual',$30000

 

SELECT * FROM ProductAlpha ORDER BY ProductID

GO

/*

ProductID   ProductName             Price       ModifiedDate

1           BMW 330i automatic      50000.00    2010-05-01

2           BMW 330i manual         49000.00    2010-05-01

3           BMW 528i automatic      60000.00    2010-05-01

4           BMW 128i manual         30000.00    2010-05-01

*/

DROP TABLE ProductAlpha

------------

 

-- SELECT INTO table create for testing

USE tempdb

SELECT ProductID, ProductName=Name, ListPrice

INTO Product

FROM AdventureWorks2008.Production.Product

WHERE ListPrice > 0

--(304 row(s) affected)

SELECT MAX (ProductID) FROM Product

GO

-- 999

-- CHECKIDENT METHOD

DBCC CHECKIDENT('dbo.Product', RESEED, 2000)

GO

/*

Checking identity information: current identity value '999',

current column value '2000'

*/

INSERT Product(ProductName, ListPrice)

VALUES ('SQLUSA Model Battery Assist Touring Bike Red 36', 2399.00)

GO

SELECT SCOPE_IDENTITY()

GO

-- 2001

SELECT MAX (ProductID) FROM Product

GO

-- 2001

 

-- IDENTITY INSERT METHOD

SET IDENTITY_INSERT dbo.Product ON

GO

INSERT Product(ProductID, ProductName, ListPrice)

VALUES (1500, 'SQLUSA Model Electric Mountain Bike Gray 42', 3399.00)

GO

SELECT SCOPE_IDENTITY()

GO

-- 1500

SET IDENTITY_INSERT dbo.Product OFF

GO

DROP TABLE tempdb.dbo.Product

 

Related articles:

 

DBCC CHECKIDENT (Transact-SQL)

 

 

Order SQL 2008 GRAND SLAM Today!
SQLUSA.com Home Page
SQL Server Training at www.sqlusa.com.
Microsoft SQL Server 2012 Training Videos at www.sqlusa.com.
SQL Server 2008 Video Training at www.sqlusa.com.
SQL Server 2005 Training Videos at www.sqlusa.com.
Accounting
Administrative
Advertising
Arts
Architecture
Banking
Business Intelligence
Career Jobs
Celebrity
Computer
Consulting
Customer Service
Education
Engineering
Entertainment
Entry Level
Executive
Federal
Finance
Government
Hardware
Healthcare
Hospital
Human Resources
Information Technology
Insurance
Internet
Job Openings
Laboratory
Law Enforcement
Legal
Logistics
Manufacturing
Marketing
Medical
Military
Nursing
Pharmaceutical
Physician
Public Relations
Publishing
Real Estate
Restaurant
Retail
Sales
Social Media
Software
SQL Database
Telecomm
Therapist
Training
Transportation
Truck Driver
Travel
Web
Work from Home

FREE SS SQL / BI OLAP Short Videos on YOUTUBE.com

Microsoft Community Contributor 2011 Microsoft Community Contributor 2012

Search SQLUSA FREE SQL Server Articles & FREE T-SQL Scripts

JOIN US ON TWITTER

Copyright 2005-2012, SMI Corp. All Rights Reserved.

SQL Server 2012 is a program product of Microsoft Corporation.
SQL Server 2008 is a program product of Microsoft Corporation.
SQL Server 2005 is a program product of Microsoft Corporation.
SQL Server 2000 is a program product of Microsoft Corporation.