跳到主要内容

UPDATE

使用新值修改表中的行。

原子操作

Databend 通过原子操作确保数据完整性。插入、更新、替换和删除操作要么完全成功,要么完全失败。

语法

UPDATE <table_name>
SET <col_name> = <value> [ , <col_name> = <value> , ... ]
[ WHERE <condition> ]

示例

-- 创建一个表
CREATE TABLE bookstore (
book_id INT,
book_name VARCHAR
);

-- 插入值
INSERT INTO bookstore VALUES (101, 'After the death of Don Juan');
INSERT INTO bookstore VALUES (102, 'Grown ups');
INSERT INTO bookstore VALUES (103, 'The long answer');
INSERT INTO bookstore VALUES (104, 'Wartime friends');
INSERT INTO bookstore VALUES (105, 'Deconstructed');

-- 更新前显示表
SELECT * FROM bookstore;

101|After the death of Don Juan
102|Grown ups
103|The long answer
104|Wartime friends
105|Deconstructed

-- 更新一本书(Id: 103)
UPDATE bookstore SET book_name = 'The long answer (2nd)' WHERE book_id = 103;

-- 更新后再次显示表
SELECT * FROM bookstore;

101|After the death of Don Juan
102|Grown ups
103|The long answer (2nd)
104|Wartime friends
105|Deconstructed
这篇文章对您有帮助吗?
Yes
No
开始使用 Databend Cloud
低成本
快速分析
多种数据源
弹性扩展
注册