Hi,

I am learning SQL.
The following lines do not yield any error in SQLite.
However, the foreign key in table "ref_foo" has four columns, and references 
table "foo" which has only 3 columns. Why is it possible?
This is just a dummy example to understand what happens with composite 
foreign keys.

Thanks in advance,

Julien

PRAGMA foreign_keys = ON;
CREATE TABLE foo ( id_foo1 INTEGER NOT NULL
                    , id_foo2 INTEGER NOT NULL
                    , id_foo3 INTEGER NOT NULL
                    , PRIMARY KEY ( id_foo1, id_foo2, id_foo3 ) );

CREATE TABLE ref_foo (
  id_reffoo INTEGER NOT NULL
  , id_foo1 INTEGER NOT NULL
  , id_foo2 INTEGER NOT NULL
  , id_foo3 INTEGER NOT NULL
  , PRIMARY KEY ( id_reffoo, id_foo1 )
  , FOREIGN KEY ( id_reffoo, id_foo1, id_foo2, id_foo3 ) REFERENCES foo ON 
UPDATE CASCADE ON DELETE CASCADE
);

-- 
python -c "print ''.join([chr(154 - ord(c)) for c in '*9(9&(18%.\
9&1+,\'Z4(55l4('])"

"When a distinguished but elderly scientist states that something is
possible, he is almost certainly right. When he states that something is
impossible, he is very probably wrong." (first law of AC Clarke)

_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to