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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Auto generated number 1

Status
Not open for further replies.

Mun

Programmer
Mar 5, 2003
46
0
0
US
Hello All,
How do I create auto number in SQL Server (similar to autonumber in MS-Acces and generating a sequence in oracle). In my code I have a field Emp_No which needs be generated automatically every time we insert a record in to the table.Any help is appreciated. thanks in advance.


 
Set the fields Identity property to Yes. For more info search for 'Identity property' in BOL.
 
To explain in detail, be sure your column data type is set to "int" with "Allow Nulls" UNchecked. Then, in the column properties at the bottom, for Identity select "Yes (not for replication)", set your Identity Seed to the number you want to start counting from, and the Identity Increment to the value that you want the Seed to increase by each time.

Hope this helps!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top