So you want to take the balance from some other row, and insert a new row using that balance?
In that case, you need to lock the whole table, or you need a proper transaction interface, with read consistency. This implies either locking the whole table with a MyISAM table type or using an InnoDB table. Dean Harding. > -----Original Message----- > From: Bryan Waters [mailto:[EMAIL PROTECTED] > Sent: Sunday, 23 February 2003 1:33 pm > To: [EMAIL PROTECTED] > Subject: Re: Cumulative Balance Field > > That won't exactly work...first I insert the record...then I update the > balance from the previous record? What if another record is inserted in > between? I know I can lock the tables but i'm trying to avoid that if at > all possible even for a short period of time. > > I have to read the previous balance from the last record inserted, insert > the new record with the new balance and hope something doesn't get > inserted > in between the read and the insert...oh yeah...hopefully using MyISAM > tables. > > > ""Dean Harding"" <[EMAIL PROTECTED]> wrote in message > news:<[EMAIL PROTECTED]>... > > MySQL guarantees that individual statements are atomic, so you can use > > something like this: > > > > UPDATE mytable SET balance = balance + 100 > > > > Of course, you'd have to provide the right WHERE clause... > > > > Dean Harding. > > > > > -----Original Message----- > > > From: Bryan Waters [mailto:[EMAIL PROTECTED] > > > Sent: Sunday, 23 February 2003 11:40 am > > > To: '[EMAIL PROTECTED] Mysql. Com' > > > Subject: Cumulative Balance Field > > > > > > I want to keep a cumulative balance field in a mysql table. How do I > > do > > > this without corruption... > > > > > > if the table looks like this: > > > > > > datetime,desc,amount,balance > > > > > > How can I insert a new record setting the balance field to the last > > > balance > > > value + amount and not have data corruption if multiple inserts are > > > happening on different connections? > > > > > > > > > --------------------------------------------------------------------- > > > Before posting, please check: > > > http://www.mysql.com/manual.php (the manual) > > > http://lists.mysql.com/ (the list archive) > > > > > > To request this thread, e-mail <[EMAIL PROTECTED]> > > > To unsubscribe, e-mail <mysql-unsubscribe- > > > [EMAIL PROTECTED]> > > > Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php > > > > > > > > --------------------------------------------------------------------- > > Before posting, please check: > > http://www.mysql.com/manual.php (the manual) > > http://lists.mysql.com/ (the list archive) > > > > To request this thread, e-mail <[EMAIL PROTECTED]> > > To unsubscribe, e-mail > <[EMAIL PROTECTED]> > > Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php > > --------------------------------------------------------------------- Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php