MySQL Forums
Forum List  »  German

Re: Eigener Primärschlüssel
Posted by: Benjamin Andreas
Date: October 08, 2008 06:41AM

Hartmut Holzgraefe Wrote:
-------------------------------------------------------
> Benjamin Andreas Wrote:

> Besser wäre in Deinem Fall aber eine zusätzliche
>
> Sequenztabelle in der Du die ID hochzählst, etwa
> so:
>
> BEGIN TRANSACTION;
> SELECT id FROM sequence_table WHERE sequence_id
> = ... FOR UPDATE;
> UPDATE sequence_table SET id = id + 1 WHERE
> sequence_id = ...;
> COMMIT;
>
> Mit SELECT ... FOR UPDATE bekommst Du row level
> write locks statt gleich die ganze Tabelle zu
> sperren
> und solche row level locks gelten auch
> clusterweit.

Das klingt gut. Erzeuge ich dann wie folgt einen neuen Datensatz?

BEGIN TRANSACTION;
INSERT INTO xyz (ID, ...) VALUES((SELECT id FROM sequence_table WHERE
sequence_id = ... ), ...);
SELECT id FROM sequence_table WHERE sequence_id = ... FOR UPDATE;
UPDATE sequence_table SET id = id + 1 WHERE sequence_id = ...;
COMMIT;

Also erst einen Datensatz mit der aktuellen ID aus der Sequenz-Tabelle erzeugen und in der gleichen Transaktion anschliessend die ID um 1 inkrementieren?

Options: ReplyQuote


Subject
Views
Written By
Posted
6471
October 07, 2008 06:39AM
3181
October 07, 2008 06:56AM
2476
October 08, 2008 06:29AM
2562
October 08, 2008 06:54AM
2485
October 08, 2008 07:11AM
Re: Eigener Primärschlüssel
2572
October 08, 2008 06:41AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.