Jump to content

Primary & Foreign Keys


23.12.2012

Recommended Posts

I'm currently going through a book which teaches you both PHP and MySQL, and I'm having a hard time going through the chapter which describes the KEYs and their use. The question is how do we create a foreign key?I had a look over some pieces of code, and as far as I can say, being given a test_db database, we've got two tables: primary_table and foreign_table. The former has a primary key called "id". The latter has only got a column named "id", and that's how we define a foreign key. In other words, SQL links them by itself. Am I right, or have I got it wrong? Any input is highly appreciated. Thanks in advance!

Link to comment
Share on other sites

It doesn't link it, you have to explicitly say you want to create a foreign key. If you're using MySQL, keep in mind that only the InnoDB engine supports foreign keys. A foreign key also does not need to have the same name as the column it references.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...