Niet the Dark Absol
Niet the Dark Absol

Reputation: 324650

How efficient are foreign keys?

Very simple question: Which is more efficient?

  1. A DELETE query on a parent table, followed by a DELETE query on a child table
  2. A DELETE query on a parent table that results in a foreign key deleting rows from a child table

To explain further, I'm working with very large tables (holding a few million rows), and I'm just wondering if the integrity offered by foreign keys is worth the extra work that MySQL has to do, over just remembering to update/delete child tables. I'd like to know before I actually go ahead and update to use foreign keys ;)

Upvotes: 4

Views: 90

Answers (1)

user207421
user207421

Reputation: 310915

Whatever you think you can code yourself, the database can do at least as well, and without having to use the network to do it.

Use the foreign keys.

Upvotes: 3

Related Questions