Recent Posts
													
											
												
												
													Recent Comments
													
											
												
												
											
									HEROJOON 블로그(히로블)
Insert문 실행 후 PK ID 조회하기 본문
반응형
    
    
    
  Insert문 실행 후 PK ID 조회하기
-- Insert Query의 ID 조회
SELECT LAST_INSERT_ID();
예시
-- Insert Query (Auto Increment 사용)
INSERT INTO board (id, title, content, user, create_dt)
VALUES  (NULL, 'hello', 'happy christmas!!', 'herojoon', NOW());
-- Insert Query의 ID 조회
SELECT LAST_INSERT_ID();
/* 
Insert Query
(Auto Increment 사용 중 해당 ID값을 입력하여 Insert하여도 
Insert Query문이 성공하며 아래 LAST_INSERT_ID 조회에서도 값이 잘 나옵니다.)
*/
INSERT INTO board (id, title, content, user, create_dt)
VALUES  (1, 'hello', 'happy christmas!!', 'herojoon', NOW());
-- Insert Query의 ID 조회
SELECT LAST_INSERT_ID();반응형
    
    
    
  'DB' 카테고리의 다른 글
| Mysql 여러 줄 Insert 하기 (3) | 2023.01.26 | 
|---|---|
| Mysql 변수 사용하기 (0) | 2023.01.26 | 
| java.sql.SQLException: Incorrect string value: 에러 해결 (0) | 2022.03.29 | 
| Mysql Datetime Function 더하기, 빼기 (1) | 2021.02.02 | 
| Mysql [Error Code: 1175] update safe mode 해제 (0) | 2020.04.21 | 
			  Comments