Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert an auto-incremented primary key into an Access table

We have a giant table in an Access database with over 500k records and no PK. Is it possible to insert an auto-incrementing primary key column into an already existing Access table?

like image 653
NealR Avatar asked Sep 26 '12 20:09

NealR


People also ask

How do I make the primary key AutoNumber in Access?

In the Data Type field, click the drop-down arrow and click AutoNumber. Under Field Properties, in New Values, click Increment to use incrementing numeric values for the primary key, or click Random to use random numbers.

How do I add an auto increment to an existing table?

To add a new AUTO_INCREMENT integer column named c : ALTER TABLE t2 ADD c INT UNSIGNED NOT NULL AUTO_INCREMENT, ADD PRIMARY KEY (c); We indexed c (as a PRIMARY KEY ) because AUTO_INCREMENT columns must be indexed, and we declare c as NOT NULL because primary key columns cannot be NULL .

How do I change my primary key to auto increment?

To change a primary key to auto_increment, you can use MODIFY command. Let us first create a table. Look at the above sample output, StudentId column has been changed to auto_increment.

Does primary key auto increment?

Auto-increment allows a unique number to be generated automatically when a new record is inserted into a table. Often this is the primary key field that we would like to be created automatically every time a new record is inserted.


1 Answers

Yes, it is and can be done quite simply by editing the table and adding an autoincrement type field. The only rule is that you can only have one autoincrement per table.

autoincrement

like image 117
Fionnuala Avatar answered Nov 22 '22 14:11

Fionnuala