Upsert 란
Update + Insert 를 합친 말로 중복되는 값이 있다면 update를 하고, 중복되는 값이 없다면 Insert를 실행한다.
* 중복되는 값의 구분은 Unique Key의 값을 기준으로 한다.
INSERT INTO t_pin_auth_info(user_id, auth_type, auth_code, status, info)
VALUES(#{userId}, #{authType}, #{authCode}, #{status}, #{info})
ON DUPLICATE KEY UPDATE
<if test="status != null">
status = #{status},
</if>
<if test="authCode != null">
auth_code = #{authCode},
</if>
<if test="info != null">
info = #{info},
</if>
update_time = NOW()
***위와 같은 경우, user_id가 unique key로 설정되어야 한다. 그렇지 않을 경우, 같은 값이 중복적으로 insert 된다.
[DB] 계좌 발급 시, 동시성 이슈 (2) | 2024.01.04 |
---|---|
[Mysql] 이모지 삽입 관련 (0) | 2023.08.30 |
[mysql] SELECT command denied to user 'user'@'localhost' for table (0) | 2023.08.21 |
[MYSQL] SELECT 결과 UPDATE 시키기 (0) | 2023.08.10 |
[Cache] 캐싱 전략2 (0) | 2023.05.25 |