- 先刪除原來的資料
- 再新增新的資料
REPLACE INTO table(column_list)
VALUES(value_list);
- 只有欄位是PRIMARY KEY or UNIQUE 才可以使用REPLACE語法
CREATE TABLE IF NOT EXISTS positions (
id INTEGER PRIMARY KEY,
title TEXT NOT NULL,
min_salary NUMERIC,
UNIQUE(title)
);
INSERT INTO positions (title, min_salary)
VALUES ('DBA', 120000),
('Developer', 100000),
('Architect', 150000);
SELECT * FROM positions;
REPLACE INTO positions (title, min_salary)
VALUES('Full Stack Developer', 140000);
REPLACE INTO positions (title, min_salary)
VALUES('DBA', 170000);