Making a FOREIGN KEY on Access

Viewed 574

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 INTEGER
       CONSTRAINT fkEductionID FOREIGN KEY (Eduction_ID) REFERENCES Eduction,
     Geography_ID INTEGER
        CONSTRAINT fkGeographyID  FOREIGN KEY (Geography_ID) REFERENCES 
        Geography,
     Demographic_ID INTEGER
        CONSTRAINT fkDemographicID  FOREIGN KEY (Demographic_ID) REFERENCES 
        Demographic,
     Economy_ID INTEGER
        CONSTRAINT fkEconomyID  FOREIGN KEY (Economy_ID) REFERENCES Economy
     );

enter image description here

Here is when I added more commas enter image description here

1 Answers

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)
Related