On May 31, 4:57 pm, Ravi <ra.ravi.... (AT) gmail (DOT) com> wrote:
Quote:
Suppose I want a column in my table to reference two other columns of
other two tables (of course datatypes are same, and the other two
columns are primary key in their respective relations). How can I
enforce this using SQL? |
CREATE TABLE <TABLE_NAME>
(
<COLUMN 1> <TYPE>,
<COLUMN 2> <TYPE>,
....
<COLUMN N> <TYPE>
FOREIGN KEY (<COLUMN NAME BEING REFERENCED>) REFERENCES
<OTHER_TABLE_NAME> (<COLUMN NAME BEING REFERENCED>),
FOREIGN KEY (<COLUMN NAME BEING REFERENCED>) REFERENCES
<OTHER_TABLE_NAME> (<COLUMN NAME BEING REFERENCED>)
);
This will do. & if you want to give this constraint a name, so that
you can later on remove or modify it, you can give it a name by
CONSTRAINT <CONSTRAINT NAME> FOREIGN KEY...
this constraint name should be unique within a schema.