 |
|
 |
neutrall Level: Scholar

 Registered: 28-03-2004 Posts: 43
|
Re: A Many to Many link in MySQL
I think I've found what I was serching for, it's the cascading command. I first need to have my many-to-many table use a Foreign key, then use the CASCADE command : Syntax from the MySQL reference book :
CREATE TABLE product (category INT NOT NULL, id INT NOT NULL,
price DECIMAL,
PRIMARY KEY(category, id)) TYPE=INNODB;
CREATE TABLE customer (id INT NOT NULL,
PRIMARY KEY (id)) TYPE=INNODB;
CREATE TABLE product_order (no INT NOT NULL AUTO_INCREMENT,
product_category INT NOT NULL,
product_id INT NOT NULL,
customer_id INT NOT NULL,
PRIMARY KEY(no),
INDEX (product_category, product_id),
FOREIGN KEY (product_category, product_id)
REFERENCES product(category, id)
ON UPDATE CASCADE ON DELETE RESTRICT,
INDEX (customer_id),
FOREIGN KEY (customer_id)
REFERENCES customer(id)) TYPE=INNODB; |
____________________________
A Stick give a wise man something to think about... and a fool, something to put in is mouth.
|
|
18-04-2005 at 02:40 PM |
|
|
|
|
 |
 |