1

I have 2 tables, A and B. A and B are have three columns.

Here is the structure of A:

id,name,phone

Here is the structure of B:

id,Aid,name

The "Aid" is related to "id" of table A. you know, foreign key. The "id" of table A is auto_inc, but I want to reindex it and change "Aid" of table B at the same time. How can I do?

casper
  • 449
  • 7
  • 20
  • 1
    you can add ON UPDATE CASCADE in your table B. – Suchit kumar Oct 17 '16 at 10:59
  • But reindexing is not really a good practice in general. PKs are supposed to be durable. – Shadow Oct 17 '16 at 11:00
  • visit http://dba.stackexchange.com/questions/74627/difference-between-on-delete-cascade-on-update-cascade-in-mysql – Suchit kumar Oct 17 '16 at 11:01
  • Thanks for you guys. – Legend Chen Oct 17 '16 at 11:02
  • Before doing anything, you should really question whether you know what you're doing. From the question you presented, it appears you aren't aware that you should **never**, in any circumstances, fiddle with the value of a primary key. You don't have to trust several people here who told you not to do it, it's your project and your application, but there are reasons we never touch primary keys. It's like fiddling with someone's DNA and expecting nothing will ever go wrong from doing so. – Mjh Oct 17 '16 at 11:59

0 Answers0