Re: UPDATE lot of registers

From: Date: Mon, 19 Oct 2009 21:44:50 +0000
Subject: Re: UPDATE lot of registers
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-46584@lists.php.net to get a copy of this message
Emiliano Boragina wrote:
Hello everyone… I dont know how to update a lot of registers on one table. I have two tables: Students and Signatures STUDENTS has got: id / name / signature SIGNATURES has got: id / name / classroom I want to use words and not numbers to write the signature on the STUDENTS table. I’ve got a long list with signatures, and I must to change one signature... How do I do update SIGNATURE AND STUDENTS tables o sam time if 100 students has got the same signature and must update automatically?
The better question would be why do you need to update two tables with the same information? Updating two tables at the same time will require using a transaction. If you're using mysql, this means the table has to be an 'innodb' table. The default 'myisam' doesn't support transactions. If you don't use a transaction, you'll potentially lose your changes. update signatures set name='New name here' where id in (1,2,3,4,5,6,7,8,9,10); server dies (power loss, hard drive crash, someone reboots it) after it updates record 5 but before it updates record 6. You now have half the table updated. Even worse would be it updates the first table but not the second - now your data is inconsistent. You can update multiple records at once quite easily. Assuming 'id' is a unique (or primary) key: Begin; update signatures set name='New name here' where id in (1,2,3,4,5,6,7,8,9,10); update students set name='New name here' where id in (1,2,3,4,5,6,7,8,9,10); commit; -- Postgresql & php tutorials http://www.designmagick.com/

« previous php.db (#46584) next »