Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Autonumber / Sequences In SQL Server

Status
Not open for further replies.

Toyman

Programmer
Jun 19, 2001
68
GB
Hi All

How do I create an auto-number or Sequence datafield in SQL Server

Thanks
Toyman
 
Use the IDENTITY property with CREATE TABLE.

This example creates a new table using the IDENTITY property for an automatically incrementing identification number.

USE pubs

IF EXISTS(SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME = 'new_employees')
DROP TABLE new_employees
GO

CREATE TABLE new_employees

(id_num int IDENTITY(1,1),
fname varchar (20),
minit char(1),
lname varchar(30)
)


Rick.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top