Inserting into multiple tables...
Posted: Thu Nov 10, 2005 11:59 pm
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
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