Page 1 of 1
foreign key
Posted: Mon Feb 12, 2007 1:08 am
by siyaco
i want to make a database which have two tables like this;
customers(customerid, name, address, city)
orders(orderid, customerid, amount, date)
you see i want to make customerid in customers and orderid in orders primary keys for those tables. i can do it.
and i want customerid in orders to be foreign key. but i can't do it. how can make it as a foreign key?
thank all in advance
Posted: Mon Feb 12, 2007 6:13 am
by Hornet83
As far as I know, foreign keys are not supported in non-InnoDB storage engines. As long as you are careful to join on the required keys in your SQLs, there is no need to define the customerid attribute as foreign in the orders entity.[/i]
Posted: Mon Feb 12, 2007 6:30 am
by siyaco
Hornet83 wrote:As far as I know, foreign keys are not supported in non-InnoDB storage engines. As long as you are careful to join on the required keys in your SQLs, there is no need to define the customerid attribute as foreign in the orders entity.[/i]
it may be the main reason. because i found a command which ends InnoDB(... FOREIGN KEY (customer_id)
REFERENCES customer(id)) ENGINE=INNODB;) . but i did not understand why i don't need foreign key, as i have understood from the book i studied (php and mysql laura thomson, luke welling) it is necessary. and the other, in phpmyadmin there is button to make something to primary key, but non to make it foreign key. may be it relates with innodb engine again
thanks all in advance
Posted: Mon Feb 12, 2007 9:19 am
by feyd
InnoDB has automatic foreign keys. MyISAM supports foreign keys, but not in an automatic fashion. In fact, you make the link on your own.