Inserting foreign keys with single query
Inserting foreign keys with single query
Hi,
Can anybody tell me how to insert foreign keys with a single query?
Suppose I have 2 tables, A and B. A.pid is table A's primary key, and B.fid is B's foreign key, referencing a row in A.
CREATE TABLE A (
pid INT NOT NULL AUTO_INCREMENT,
name VARCHAR(32),
PRIMARY KET(pid)
);
CREATE TABLE B (
pid INT NOT NULL AUTO_INCREMENT,
PRIMARY KET(pid)
);
I've tried this query but the server whines (at least w/ MySQL 3.23.58):
INSERT INTO B values (
SELECT pid FROM A WHERE name='something'
);
FYI I'm using MySQL 3.23.58 on Win98se box.
Plz help.
TIA
Subject
Written By
Posted
Inserting foreign keys with single query
August 26, 2004 02:05PM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.