Can you actually make relationships between tables in MySql???

i've looked all over the interent and all i can find is detail on what a relationship is

pleeeeease help! am i barking up the wrong tree?

Recommended Answers

All 2 Replies

Search for foreign keys.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.