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

Id there an autonumber datatype in SQL Server?

Status
Not open for further replies.

bongmarley

Programmer
Oct 21, 2002
74
CA
Is there an equivalent to Access's autonumber in SQL Server
 
I am creating database in SQL Server by importing an existing database from Access. I want to be able to still have ID as an autonumber. Is this possible?
 
yes the way that SQL server does it is you use a numeric datatype usually int then you set it as an Identity.

an exapmle of how to do this is shown in the following create table statement.

CREATE TABLE [dbo].[CityAirport] (
[CityID] [int] NULL ,
[CommercialAirportID] [nvarchar] (4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[CityAirportID] [int] IDENTITY (1, 1) NOT NULL
) ON [PRIMARY]

City AirportID is the autonumbering field. The (1,1) after IDENTITY indicates the the first number should be 1 and that the field should increment by 1 each time.
 
I am creating the table by just importing existing tables fromm Access. Because I did not create the table only import it in can I change a field to set an Identity in design view or can this only be done by creating your own table.
 
yes you can change it in design view, you'll see it down at the bottom of the form, just change no to yes and adjust the Identity seed (starting value, but you can leave it at oneif youwant the next value) and Identity increment (againleave at the default if you want to increment by 1 number each time.)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top