Page 1 of 1

Inserting into multiple tables...

Posted: Thu Nov 10, 2005 11:59 pm
by poisedforflight
I am writing some code to take notes. At this point I can enter the notes and signify if they are a subchapter or a new chapter. if its a new chapter topicParent is null and if it is a subchapter topicParent is equal to the topicID of its "parent chapter".

I have two tables:

CREATE TABLE topicsTable (
topicId INT NOT NULL AUTO_INCREMENT,
topicName VARCHAR(50),
topicParent INT NULL,
PRIMARY KEY (topicID),
);

CREATE TABLE entryTable(
entryId INT NOT NULL AUTO_INCREMENT,
topicId INT,
topicBody TEXT,
PRIMARY KEY (entryId),
FOREIGN KEY (topicId) REFERENCES topicsTable (topicId)
);

What I am trying to figure out is how to place the body of the notes in the entryTable and reference it to the topicId, while placing the topicName and topicParent in the topicsTable. I guess what I am asking is whether there is a way to conjoin the INSERT statement, or if it has to be 2 statements.

???

-Jason

Posted: Fri Nov 11, 2005 12:17 am
by s.dot
you're inserting into two tables so you will need two queries.

Posted: Fri Nov 11, 2005 1:37 am
by n00b Saibot
UNION maybe :?

Posted: Fri Nov 11, 2005 2:57 am
by hessodreamy
The manual makes no refrence to multiple table inserts, so my guess is you'll need 2 queries.