[DB] Upsert

2017. 3. 30. 18:17프로그래밍/Database

728x90
728x90

용어를 찾아보자

  • 오늘 회사에서 Upsert란 용어를 알게되어 찾아보게 되었다.
  • https://wiki.postgresql.org/wiki/UPSERT
  • definition 설명을 보면
      _" "UPSERT" is a DBMS feature that allows a DML statement's author to atomically either insert a row, or on the basis of the row already existing, UPDATE that existing row instead, while safely giving little to no further thought to concurrency. One of those two outcomes must be guaranteed, regardless of concurrent activity, which has been called "the essential property of UPSERT". Examples include MySQL's INSERT...ON DUPLICATE KEY UPDATE, or VoltDB's UPSERT statement. "_
  • 업데이트를 진행할 때, 만족하는 로우가 있다면 업데이트를 하고 없다면 인서트를 하는 것을 의미.
  • 다른 sql에서는 실제 키워드로 존재해서 사용할 수 있는듯 하다.

회사코드를 보니

  • UPDATE 후 @@ROWCOUNT가 1인지 체크하고 INSERT 진행. 이런 형태로 구현되어있다.
728x90
반응형

'프로그래밍 > Database' 카테고리의 다른 글

[mssql2008] db log 용량 줄이기  (2) 2016.12.23
Index(mysql)  (2) 2015.08.18
데이터베이스 고급 기능  (0) 2015.08.13
저장프로시저(MS-SQL 환경)  (0) 2015.08.12
관계형 데이터베이스 모델과 언어  (0) 2015.08.11
데이터 모델링과 설계  (0) 2015.08.11
정보 시스템  (0) 2015.08.11