foreign key

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
siyaco
Forum Commoner
Posts: 26
Joined: Mon Feb 05, 2007 1:36 am
Location: Kurdistan Mountains

foreign key

Post 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
User avatar
Hornet83
Forum Newbie
Posts: 4
Joined: Mon Feb 12, 2007 2:03 am
Location: Melbourne, AUS

Post 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]
siyaco
Forum Commoner
Posts: 26
Joined: Mon Feb 05, 2007 1:36 am
Location: Kurdistan Mountains

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
Post Reply