mysql, mariadb 채번 방법 또는 auto increment field -> LAST_INSERT_ID의 thread(concurrent) safe 여부

  • 채번할때, last_insert_id 로 select되는 값은 connection basis라는...


** 즉, 해당 connection에서 증가된 값으로 select 된다는...


* 단, 같은 connection에서 여러번 insert를 해도 첫번째 insert시 증가한 auto_increment 값만 select한다는....


** commit 시점이 중요한듯(?)

from : https://dev.mysql.com/doc/refman/5.0/en//information-functions.html#function_last-insert-id


The ID that was generated is maintained in the server on a per-connection basis. This means that the value returned by the function to a given client is the first AUTO_INCREMENT value generated for most recent statement affecting an AUTO_INCREMENT column by that client. This value cannot be affected by other clients, even if they generate AUTO_INCREMENT values of their own. This behavior ensures that each client can retrieve its own ID without concern for the activity of other clients, and without the need for locks or transactions.


The value of LAST_INSERT_ID() is not changed if you set the AUTO_INCREMENT column of a row to a non-“magic” value (that is, a value that is not NULL and not 0).


Important

If you insert multiple rows using a single INSERT statement, LAST_INSERT_ID() returns the value generated for the first inserted row only. The reason for this is to make it possible to reproduce easily the same INSERTstatement against some other server.


댓글

이 블로그의 인기 게시물

엑셀(excel) 비쥬얼 베이직(visual basic, vba) 심플 실비(실손보험, 실손의료비) 계산식

아트월에 날짜, 시간 나오는 LED 벽시계 설치시 케이블(전선)이 두꺼워서 틈새(홈)에 매립이 안되는 경우 랜선(lan cable, lan선) 이용시 주의사항

신한투자증권(주) 님이 세금계산서를 발행하였습니다. TaxBill365 관련 안전한 메일인지 여부?