23.12.2012 Posted September 10, 2009 Report Share Posted September 10, 2009 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 More sharing options...
justsomeguy Posted September 10, 2009 Report Share Posted September 10, 2009 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 More sharing options...
23.12.2012 Posted September 10, 2009 Author Report Share Posted September 10, 2009 And how do I explicitly create the foreign key? Because the book does not seem to cover that. Thanks! Link to comment Share on other sites More sharing options...
justsomeguy Posted September 10, 2009 Report Share Posted September 10, 2009 Check here:http://dev.mysql.com/doc/refman/5.1/en/inn...onstraints.html Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now