Inserting into multiple tables...

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
poisedforflight
Forum Newbie
Posts: 1
Joined: Mon Nov 07, 2005 4:07 pm

Inserting into multiple tables...

Post 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
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

you're inserting into two tables so you will need two queries.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

UNION maybe :?
hessodreamy
Forum Commoner
Posts: 58
Joined: Wed Apr 20, 2005 8:11 am

Post by hessodreamy »

The manual makes no refrence to multiple table inserts, so my guess is you'll need 2 queries.
Post Reply