8 Years
Discussion Span
Last Post by drjohn

You can do it the easy way and the correct way - most people do it the easy way.
Simply use the primary key from one table as a field in the other table. there is now a simple relationship established, enabling you to carry out joins. However relational integrity is not necessarily enforced, as that depends on the type of table you used when first defining the table.

The commonest default table type is MyISAM, which is fast but doesn't enforce relational integrity. But joins etc will work exactly are advertised, if you make sure the foreign key is entered propery ie no misspelling or typos.

The InnoDB and BDB storage engines provide transaction-safe tables. To maintain data integrity, InnoDB also supports FOREIGN KEY referential-integrity constraints. so here you can't get away with an illegal non-existent foreign key. But its slower.

So the perfect way is to use InnoDB, but you can get away with using MyISAM.

If you use InnoDB, you have to declare the foreign key and the table it relates to.

Edited by drjohn: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.