views:

45

answers:

2

How can I create a table with autoincrement in access. Here is what I have been doing but not working.

CREATE TABLE People_User_Master(  
    Id INTEGER primary key AUTOINCREMENT,
    Name varchar(50),
    LastName varchar(50), 
    Userid varchar(50) unique,
    Email varchar(50),
    Phone varchar(50),
    Pw varchar(50),
    fk_Group int,
    Address varchar(150)  
)
+1  A: 

Try adding the constraint at the end

CREATE TABLE People_User_Master(   
Id AUTOINCREMENT 
  , Name varchar(50)   
, LastName varchar(50)   
, Userid varchar(50) unique   
, Email varchar(50)   
, Phone varchar(50)   
, Pw varchar(50)   
, fk_Group int   
, Address varchar(150)
, CONSTRAINT id_pk PRIMARY KEY(Id)

)

Updated to fit the actual answer (the definition of INTEGER on the AUTOINCREMENT column was not allowed). Leaving PRIMARY KEY at the same line as Id AUTOINCREMENT does work.

Lex
doesn't work either
Thunder
Ok, try removing the INTEGER after Id. (so the second line becomes Id AUTOINCREMENT
Lex
bingo ! it works ... please edit your answer so that I can accept it.Id AUTOINCREMENT PRIMARY KEY also worksThanks
Thunder
Great. I've updated my answer.
Lex
A: 

You can do it using IDENTITY (supported by Jet4+)

CREATE TABLE People_User_Master
(
ID IDENTITY (1, 1), 
Name ..

Failing that;

ID AUTOINCREMENT, 

Should work (note you don't specify a type)

Alex K.