Hi,

there's very much information about how transactions and locking works
in InnoDB, but maybe there's also a simple and understandable answer to
my simple question:

When I start a transaction, then find the maximum value of a column and
use that + 1 to write a new row into the table, how do transactions
protect me from somebody else doing the same thing so that we'd both end
up writing a new row with the same value?

Here's a description:

BEGIN TRANSACTION
new_id := (SELECT MAX(id) FROM table) + 1
-- some more work here
INSERT INTO table (id, ...) VALUES (new_id, ...)
COMMIT

What happens if another user does the same in that "more work" region?

(Of course, this example is pseudocode, I really have a PHP application
that does this.)

-- 
Yves Goergen "LonelyPixel" <[EMAIL PROTECTED]>
Visit my web laboratory at http://beta.unclassified.de

-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to