Is there an alternative way to use foreign keys in Myisam tables?

Asked

Viewed 474 times

2

I’m making an application and need to relate two tables, logically, could use foreign keys... The problem is that the database I am using only allows Myisam tables that do not support foreign keys like Innodb. So, how could you get around this problem without having to use Innodb tables?

1 answer

2


Foreign keys in Mysql are used to verify and ensure the referential integrity, not to do join between tables.

The only alternative is to be you do the job that is done by the database to ensure the referential integrity.

However, you can continue to do join between the tables related through these columns, in the same way as in the case of foreign keys.

that is to say:

SELECT * FROM tabell1 INNER JOIN tabela2 ON tabela1.id = tabela2.id;  

remains valid

  • 1

    That is, you need to make sure that at all points of your application that make some kind of modification in the tables involved will be guaranteed the maintenance of referential integrity. In practical terms I would choose to change the engine to Innodb, it is much simpler.

  • 2

    Not at all points, you can use Triggers in order to centralize this check. See: Enforcing Foreign Keys Programmatically in Mysql

Browser other questions tagged

You are not signed in. Login or sign up in order to post.