나의 발자취
데이터베이스 모델 설계, insert into-do update set 본문
데이터베이스 설계
요구 조건 분석(~명세서 작성) > 개념적 설계(개념 스키마, 트랜잭션 모델링, E-R 모델) > 논리적 설계 (목표 DBMS에 맞는 논리 스키마 설계, 트랜잭션 인터페이스 설계) > 물리적 설계(목표 DBMS에 맞는 물리적 구조의 데이터로 반환) > 구현
insert into product (product_id, product_name, unit_price, stock)
values(92, '불닭볶음면', 9000, 50)
on conflict (product_id)
do update set
product_name = excluded.product_name,
unit_price = excluded.unit_price,
stock = excluded.stock;
product_id 키가 같아서 충돌이 날 경우, 업데이트하는 쿼리문이다.
처음 쿼리 실행시에는 잘 들어간 것을 볼 수 있다.
아래 쿼리문을 돌리고, 다시 출력해보면 업데이트가 된다.
insert into product (product_id, product_name, unit_price, stock)
values(92, '까르보나라 불닭볶음면', 12000, 150)
on conflict (product_id)
do update set
product_name = excluded.product_name,
unit_price = excluded.unit_price,
stock = excluded.stock;
'Backend' 카테고리의 다른 글
Comments