SQL Apprentice Question
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?
Celko Answers
>> Suppose I want a column in my table to reference two other columns of other two tables (of course data types are same, and the other two columns are primary key in their respective relations). How can I enforce this using SQL? <<-
CREATE TABLE Foo
(foo_id INTEGER NOT NULL PRIMARY KEY,
..);
CREATE TABLE Bar
(_id INTEGER NOT NULL PRIMARY KEY,
..);
CREATE TABLE Foobar
(foo_id INTEGER NOT NULL
REFERENCES Foo(foo_id),
bar_id INTEGER NOT NULL
REFERENCES Bar(bar_id),
Original Source
Monday, June 04, 2007
Subscribe to:
Post Comments (Atom)
1 comment:
I think the question meant that just one column has fk to two tables, not two different columns with one fk each.
Post a Comment