Hello,

I have another "borderline" question about SQL in SQLite. Look at the 
following example

-------------------------------------------
PRAGMA foreign_keys = ON;

CREATE TABLE toto1 ( id_toto1 INTEGER PRIMARY KEY
                    , id_toto2_and_toto3 INTEGER NOT NULL
                    , FOREIGN KEY ( id_toto2_and_toto3 ) REFERENCES toto2 ON 
UPDATE CASCADE ON DELETE CASCADE
                    , FOREIGN KEY ( id_toto2_and_toto3 ) REFERENCES toto3 ON 
UPDATE CASCADE ON DELETE CASCADE );
CREATE TABLE toto2 ( id_toto2 INTEGER PRIMARY KEY
                    , name VARCHAR );
CREATE TABLE toto3 ( id_toto3 INTEGER PRIMARY KEY
                    , name VARCHAR );

-- The two following lines are needed, otherwise "foreign key constraint
-- failed" is obtained.
INSERT INTO toto2 ( name ) VALUES ( "foo" );
INSERT INTO toto3 ( name ) VALUES ( "bar" );

INSERT INTO toto1 ( id_toto2_and_toto3 ) VALUES ( 1 );
-------------------------------------------

Is this legal to have a foreign key that references several tables?

Thanks,

Julien

-- 
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