我刚开始学习如何使用SQL编写代码。我正在关注Codeacedemy.com的教程
这是我为了它的乐趣写的东西,一个简单的日期基础:
CREATE TABLE employees (id INTEGER, name TEXT, year INTEGER);
INSERT INTO employees (id, name, year) VALUES (1, 'Dave', 2010);
INSERT INTO employees (id, name, year) VALUES (2, 'Karen', 2001);
INSERT INTO employees (id, name, year) VALUES (3, 'Joe', 2009);
INSERT INTO employees (id, name, year) VALUES (4, 'Larry', 2013);
INSERT INTO employees (id, name, year) VALUES (5, 'Tammy', 2015);
INSERT INTO employees (id, name, year) VALUES (6, 'Samantha', 2005);
INSERT INTO employees (id, name, year) VALUES (7, 'Karen', 2010);
INSERT INTO employees (id, name, year) VALUES (8, 'Rick', 2011);
ALTER TABLE employees ADD COLUMN gender TEXT;
UPDATE employees
set gender = 'Male'
where id = 1;
SELECT * FROM employees;
有没有办法可以使用他们的ID一次更新多行?例如,我可以使用id 1,3,5,8,它们都将更新为“男性”。
谢谢!
答案 0 :(得分:5)
这用于使用where子句:
UPDATE employees SET gender = 'Male' WHERE id IN (1,2,3)
如果要更新表中的所有行,则:
UPDATE employees SET gender = 'Male'
答案 1 :(得分:2)