0

I would like to reference a foreign key to a primary key within the same table, using the query design mode in ms access. This is what I tried to do:

CREATE TABLE Employees ( 
P_Id INTEGER PRIMARY KEY,
super_Id INTEGER FOREIGN KEY REFERENCES Employees(P_Id)
);

However I receive a syntax error (the word FOREGIN is highlighted). Is it at all possible to perform this task in ms access?

Edit: I switched to ANSI-92, and I also tried this format:

CREATE TABLE Employees ( 
P_Id INTEGER PRIMARY KEY,
CONSTRAINT super_Id  FOREIGN KEY (Employees)
);

but I still receive an error

nafrtiti
  • 176
  • 8

1 Answers1

0

For MS Access, you need to use CONSTRAINT keyword like:

CREATE TABLE Employees ( 
   P_Id INTEGER NOT NULL,
   Super_Id INTEGER NOT NULL,

   PRIMARY KEY(P_Id),
   CONSTRAINT FK_SuperId FOREIGN KEY (Super_Id)
   REFERENCES Employees(P_Id)
);
Eray Balkanli
  • 7,752
  • 11
  • 48
  • 82