FOREIGN KEY

Description

Constraint that specifies a foreign key constraint, which requires that a group of one or more columns of the new table must only contain values that match values in the referenced column or columns of some row of the referenced table.

Click here to navigate to the Amazon Redshift docs page for this syntax.

Grammar Syntax

FOREIGN KEY (column_name [, ... ] ) REFERENCES reftable [ ( refcolumn )

Sample Source Patterns

Amazon Redshift

CREATE TABLE TABLE1
(
 COL1 INT PRIMARY KEY
);

CREATE TABLE TABLE2
(
 COL1 VARCHAR(15),
 COL2 INT,
 FOREIGN KEY (COL2) REFERENCES TABLE1(COL1)
);

Snowflake

CREATE TABLE TABLE1
(
 COL1 INT PRIMARY KEY
);

CREATE TABLE TABLE2
(
 COL1 VARCHAR(15),
 COL2 INT,
 FOREIGN KEY (COL2) REFERENCES TABLE1 (COL1)
);

Known issues

There are no known issues.

Last updated