I have a database that has several tables. Many of the tables have fields with foreign key constraints. I want to truncate the tables and then repopulate them with new data, and I also want to take off the foreign keys, as some of the relationships have changed. basically, I want to build the FK constraints up from scratch again. How can I remove the current FK constraints from all tables?
相关问题
- sqlyog export query result as csv
- NOT DISTINCT query in mySQL
- MySQL: conduct a basic search
- Why sometimes there is one of more gap(s) in the v
- mySQL alter table on update, current timestamp
I"m guessing you already found a solution, since this post is six months old, but I recently had to come up with a script to drop foreign key constraints to a particular table in MySQL, so that may help anyone else in the same boat:
To run it, simply use:
And if you don't want to keep the procedure around:
Of course if you want to drop all FK constraints to the table, you can remove the refcolumn parameter and the last line of each where clause.
You can play with the information_schema. Take a look at this page
http://dev.mysql.com/doc/refman/5.0/en/key-column-usage-table.html
then run the output generated.
You can do something similar in order to truncate all tables.
this one will truncate all tables within the specified database. So use it with care.