1

I have a database in mysql. Now in one table there is a primary key and in the other tables there are foreign keys. How do I update the primary key and have it update all the foreign keys at the same time? I remember being taught it and it being a word starting with C I think, can't remember. Oh and I don't want to individually update each table one by one.

Thanks for any help given. Arran

sbnarra
  • 556
  • 4
  • 9
  • 25
  • You cannot update primary key in any of your database table, you will need to delete the record and re-insert into your database. – Murtaza Mar 09 '12 at 11:49
  • @Murtaza This is not even remotely true. [Example Here](http://sqlfiddle.com/#!2/a2581/880) – GarethD Mar 09 '12 at 12:05
  • @GarethD - Just executed your fiddle but it did not gave me the updated Id in my select statement Result was `Record Count: 0; Execution Time: 0ms ` – Murtaza Mar 09 '12 at 12:09
  • @Murtaza scroll down further - the Recordd count: 0... is produced by the update statement. There is a further recordset produced by the second select. – GarethD Mar 09 '12 at 12:11

1 Answers1

2

You need to make sure your foreign keys have the referential triggered action ON UPDATE CASCADE.

onedaywhen
  • 55,269
  • 12
  • 100
  • 138
GarethD
  • 68,045
  • 10
  • 83
  • 123