While importing a database that has tables with foreign keys defined we get to see error “#1452 – Cannot add or update a child row: a foreign key constraint fails“.
Even while trying to delete some tables from such a database, we come across situation where we face foreign key constraint error: “#1217 – Cannot delete or update a parent row: a foreign key constraint fails“
To avoid such errors first disable the foreign key checks, then do your job of importing the database or deleting the table and finally enable the foreign key checks.
Indexes are needed to improve the performance of SELECT queries. They can be defined with table creation and also created after table creation with CREATE INDEX and ALTER TABLE statements. If during optimization you find that an index is not useful then you can DROP them using DROP INDEX or ALTER TABLE statements.
Indexes are needed to improve the performance of SELECT queries. Indexes in Mysql are just like the indexes available in books. Without indexes if we have to look for a topic in a book then we will have to go through each page content but luckily we have an index, we find the page number from the index and then open that page directly. Similarly in MySql if we have to find row(s) have a particular column value then without index on that column MySql will have to scan each row of the table to find the matching rows.
It is highly recommended that you create indices on columns of a table from which you often query the data.
Are you trying to import a MySql dump file and getting the following error: “#1452 – Cannot add or update a child row: a foreign key constraint fails”? Its because of the foreign key validation checks.
You can run the following statement to get detailed error information:
SHOW ENGINE INNODB STATUS;