如何更新主键的值?

时间:2018-11-29 14:55:13

标签: sqlite

假设我在Sqlite中有一个表:

MySingleRowtable:

+--------------+
|  someHeader  |       <-----pk
+--------------+
|     aa       |
+--------------+

如何更新主键的值?

我尝试过:

UPDATE MySingleRowtable
SET 'someHeader' = 'bb'
WHERE 'someHeader'='aa';

1 个答案:

答案 0 :(得分:0)

以下作品:-

DELETE FROM MySingleRowTable;
CREATE TABLE IF NOT EXISTS MySingleRowTable (someHeader PRIMARY KEY);
INSERT OR IGNORE INTO MySingleRowTable VALUES('aa');
SELECT * FROM MySingleRowTable;
UPDATE MySingleRowTable SET someHeader = 'bb' WHERE someHeader = 'aa';
SELECT * FROM MySingleRowTable;

enter image description here

但是,您有:-

DELETE FROM MySingleRowTable;
CREATE TABLE IF NOT EXISTS MySingleRowTable (someHeader PRIMARY KEY);
INSERT OR IGNORE INTO MySingleRowTable VALUES('aa');
SELECT * FROM MySingleRowTable;
UPDATE MySingleRowTable SET 'someHeader' = 'bb' WHERE 'someHeader' = 'aa';
SELECT * FROM MySingleRowTable;

enter image description here

也就是说,列名用单引号引起来,所以您实际上是在说

  • 仅当 someHeader (文本)为 aa 时才更新。

相对于

  • 仅当列someHeader 的内容具有值 aa 时更新。