Re: UPDATE lot of registers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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/


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux