Re: bridge tables
Posted by: Joe Celko
Date: January 03, 2007 01:33PM

Is this what you would have posted if you had bothered with DDL instead of your personal pseudo-code? Aslo, fields and columns are totally different concepts; I never heard the term "bridge table" outside of card games before.

CREATE TABLE Authors -- more than one??
(author_id INTEGER NOT NULL PRIMARY KEY,
author_name VARCHAR(25) NOT NULL,
etc.);

CREATE TABLE Books -- more than one??
(isbn CHAR(13) NOT NULL PRIMARY KEY,
book_title VARCHAR(25) NOT NULL,
etc.);

CREATE TABLE Authorship -- common name for the relationship
(author_id INTEGER NOT NULL
REFERENCES Authors(author_id)
ON DELETE CASCADE
ON UPDATE CASCADE,
isbn CHAR(13) NOT NULL
REFERENCES Books(isbn)
ON DELETE CASCADE
ON UPDATE CASCADE,
PRIMARY KEY (author_id, isbn),
author_role CHAR(3) NOT NULL, --author, co-author, contributor, editor, etc.
etc.);

>> when I enter data into the two separate tables, the identifiers do not get entered into the bridge [sic] table. <<

You have to put your work into a single transaction; insert the book data, insert yhe Authors and then insert the authorship as the last step once the two requried entities are in place. This sounds like a PHP coding problem, not SQL. Were you thinking that the relationship would appear automatically?

Options: ReplyQuote


Subject
Written By
Posted
November 15, 2006 10:36PM
November 30, 2006 05:41PM
Re: bridge tables
January 03, 2007 01:33PM


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.