Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create an AutoNumber field value in Access?

I'm trying the following:

CREATE TABLE Table1
(
    RecordNo autonumber, --error here!
    PersonId varchar(50),
    ...
)

But, there is an error.
How can I build the correct query in Access?

like image 971
Gopal Avatar asked Jul 02 '09 07:07

Gopal


People also ask

How do I set AutoNumber format in access?

Create the AutoNumber field. Switch to design view, and place your cursor next to the AutoNumber field. In the properties panel (shown below) enter 0000 next to format. Autonumbers will automatically default to 4 digits (0001, 0002, etc.)

How does AutoNumber work in access?

AutoNumber is a type of data used in Microsoft Access tables to generate an automatically incremented numeric counter. It may be used to create an identity column which uniquely identifies each record of a table. Only one AutoNumber is allowed in each table. The data type was called Counter in Access 2.0.


1 Answers

According to SQL Auto Increment a Field:

CREATE TABLE Persons
(
P_Id PRIMARY KEY AUTOINCREMENT,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Address varchar(255),
City varchar(255)
)

The MS Access uses the AUTOINCREMENT keyword to perform an auto-increment feature.

By default, the starting value for AUTOINCREMENT is 1, and it will increment by 1 for each new record.

To specify that the "P_Id" column should start at value 10 and increment by 5, change the autoincrement to AUTOINCREMENT(10,5).

Synonyms for AUTOINCREMENT include COUNTER and IDENTITY. Using IDENTITY the makes a lot of sense because it matched the @IDENTITY variable which returns the last used autonumber value.

like image 117
Eugene Yokota Avatar answered Oct 13 '22 01:10

Eugene Yokota