Microsoft Access Database Development With VBA

SQL Keywords: REFERENCES

   

Description

The REFERENCES keyword is used to create a foreign key when creating a table. The basic formula to use is:

ColumnName DataType REFERENCES ParentTableName(ForeignKeyCcolumn)

The REFERENCES keyword is required. In the ParentTableName placeholder, enter the name of the primary table that holds the information that will be accessed in the current table. In the parentheses of ParentTableName, enter the name of the primary column of the parent table. Here is an example:

CREATE TABLE Persons
(
    PersonID AUTOINCREMENT(1,1) NOT NULL,
    FirstName varchar(20),
    LastName varchar(20) NOT NULL,
    GenderID Integer REFERENCES Genders(GenderID),
    CONSTRAINT PK_Persons PRIMARY KEY(PersonID)
);
     
 

Home Copyright © 2012 FunctionX, Inc. Home