Идемпотентность DML

Рассмотрим определения идемпотентности и DML:

Идемпотентность добавления новых данных

MS Sql Server

IF NOT EXISTS(SELECT * FROM table_name WHERE condition)
BEGIN
  INSERT INTO table_name (column1, column2, ...)
  SELECT 'new_value1', 'new_value2', ...
ENDCode language: JavaScript (javascript)

Firebird

INSERT INTO table_name (column1, column2, ...)
SELECT `new_value1`, 'new_value2', ... FROM RDB$DATABASE
WHERE NOT EXISTS
  (
    SELECT 1
    FROM table_name
    WHERE condition
  );Code language: JavaScript (javascript)

MySQL

INSERT INTO `table_name` (`column1`, `column2`, ...) 
SELECT `new_value1`, 'new_value2', ... FROM DUAL 
WHERE NOT EXISTS 
  (
    SELECT 1
    FROM `table_name`
    WHERE condition
  );Code language: JavaScript (javascript)

Oracle

INSERT INTO schema.table_name (column1, column2, ...)
SELECT 'new_value1', 'new_value2', ... FROM DUAL
WHERE NOT EXISTS
  (
     SELECT 1
     FROM schema.table_name
     WHERE condition

  );Code language: JavaScript (javascript)

Добавить комментарий Отменить ответ