I am trying to make a database about countries (for a school assignment)on Access, but Access is saying that there is a syntax error in constraint clause about me using the word REFERENCES- does anyone have any ideas of how to get these FOREIGN KEYs to work? I have been trying to look it up, but to no avail (also just started working with SQL)

 Create Table Countries (Country_ID INTEGER primary key,name TEXT(255),Politics_ID INTEGER CONSTRAINT fkPoliticsID FOREIGN KEY (Politics_ID) REFERENCES Politics,Eduction_ID INTEGERCONSTRAINT fkEductionID FOREIGN KEY (Eduction_ID) REFERENCES Eduction,Geography_ID INTEGERCONSTRAINT fkGeographyID FOREIGN KEY (Geography_ID) REFERENCES Geography,Demographic_ID INTEGERCONSTRAINT fkDemographicID FOREIGN KEY (Demographic_ID) REFERENCES Demographic,Economy_ID INTEGERCONSTRAINT fkEconomyID FOREIGN KEY (Economy_ID) REFERENCES Economy);

enter image description here

Here is when I added more commasenter image description here

1

Best Answer


Here is a similar but simpler query which works in Access 2010.

Notice I defined a Politics_ID field in the Countries table to serve as the foreign key field used to reference the Politics table.

CREATE TABLE Countries(Country_ID INTEGER primary key,Country_name TEXT(255),Politics_ID INTEGER,CONSTRAINT fkPoliticsID FOREIGN KEY (Politics_ID) REFERENCES Politics);

That statement assumes the matching field in the remote table (Politics) is also named Politics_ID. However if that remote field has a different name (say Pol_ID), you can include its name after the remote table name like this:

CONSTRAINT fkPoliticsID FOREIGN KEY (Politics_ID) REFERENCES Politics (Pol_ID)