When you want to restore your mysql tables, to avoid errors, you must drop foreign key and create its again. Mysql stores foreign key constraint into information_schema.key_column_usage table. These are several steps that you can be done to drop and create foreign key:
Export foreign key script by using “select into outfile” command. For example:
select concat('alter table ',table_name,' add constraint ',
constraint_name,' foreign key(',column_name,')',
' references ',referenced_table_name,'(',
referenced_column_name,')')
into outfile 'c:/fktestdatabase.sql' from
information_schema.key_column_usage
where table_schema='testdatabase'
Note: You can use EMS Manager lite to do this method.
Drop your foreign key
Create your foreign key again by using shellexecute command. For example:
shellexecute(self.Handle,pchar('open'),
pchar('C:\Program Files\MySQL\MySQL Server 5.0\bin\mysql.exe'),
pchar('-u root -proot -h localhost -e "use testdatabase;source '+
setpath(extractfilepath(paramstr(0))+'fktestdatabase.sql;')+
'" '),
pchar('C:\Program Files\MySQL\MySQL Server 5.0\bin'),sw_show);
For further details download my application here.


>