MySQL Forums
Forum List  »  German

Re: trigger + last_insert_id
Posted by: Thomas Wiedmann
Date: May 27, 2011 10:34AM

Thomas Wiedmann Wrote:
-------------------------------------------------------

> DELIMITER $$
>
> CREATE FUNCTION my_last_insert_id_from_t1()
> RETURNS INT NOT DETERMINISTIC
> BEGIN
>
> DECLARE t1_max_a INT DEFAULT NULL;
>
> SELECT MAX(a)
> INTO t1_max_a
> FROM t1;
> RETURN t1_max_a;
> END$$
>
> DELIMITER ;

Ergänzung:

Dass ist natürlich keine "saubere" Lösung. Da nur LAST_INSERT_ID() Dir Deine letzte ID geben kann. In einer Multi-User-Umgebung liefert mein MAX(a) Vorschlag eventuell die letzte ID eines anderen Users (einer anderen Insert-Aktion).

Grüße
Thomas

Options: ReplyQuote


Subject
Views
Written By
Posted
4465
May 27, 2011 06:01AM
2099
May 27, 2011 07:02AM
Re: trigger + last_insert_id
2122
May 27, 2011 10:34AM
1851
May 28, 2011 12:55AM
1906
May 28, 2011 09:45AM


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.