REPLACE INTO
is the similar to
INSERT INTO
statement.
The difference is that it updates the record if it already exists.
It's required one of the listed columns to be a private key of the table
REPLACE INTO students (id, first_name, points)
VALUES (41, 'ილიკო', 147)
Note 1
: If primary key is not listed, it will insert the record, but if the primary key is one of the listed columns, it will update the specified row that matches the primary key.
Note 2
: If the primary key exists, all the other omitted columns will get the default values after updating the record.
Similar to the
REPLACE INTO
statement is
ON DUPLICATE KEY
.
The only difference is that on duplicate key it updates only the listed columns but omitted values stays the same
INSERT INTO students (id, first_name, points)
VALUES (41, 'გიორგი', 149)
ON DUPLICATE KEY
UPDATE first_name = 'გიორგი', points = 123