Foreign key,local key?

Posted by user198729 on Stack Overflow See other posts from Stack Overflow or by user198729
Published on 2010-03-09T02:02:37Z Indexed on 2010/03/09 2:06 UTC
Read the original article Hit count: 398

Filed under:
|
CREATE TABLE products (
     id integer unsigned auto_increment primary key
) ENGINE=INNODB;

CREATE TABLE orders (
     id integer PRIMARY KEY auto_increment,
     product_id integer unsigned,
     quantity integer,
     INDEX product_id_idx (product_id),
     FOREIGN KEY (product_id) REFERENCES products (id)
) ENGINE=INNODB;

Here the products and orders obviously have some kind of relation--foreign key relation.

Also a coin has two sides,so I'm doubting how do we say which table is the foreign key side or local key side?

© Stack Overflow or respective owner

Related posts about database

Related posts about foreign-keys