增:insert
INSERT INTO products (product_no, name, price) VALUES
(1, ‘Cheese‘, 9.99),
(2, ‘Bread‘, 1.99),
(3, ‘Milk‘, 2.99);
可以一次插入多行数据。
INSERT INTO products (product_no, name, price) VALUES (1, ‘Cheese‘, DEFAULT);
INSERT INTO products DEFAULT VALUES;
INSERT INTO products (product_no, name) VALUES (1, ‘Cheese‘);
INSERT INTO products VALUES (1, ‘Cheese‘);
插入默认值,从左向右赋值,无值的或未指定值的赋默认值,或显式把所有列赋默认值。
?
?
删:delete
DEDELETE FROM products;
LETE FROM products WHERE price = 10;
删除满足where条件的记录或
删除所有记录(如果不提供where条件)
?
?
改:update
To update existing rows, use the?UPDATE?command. This requires three pieces of information:
- The name of the table and column to update
- The new value of the column
- Which row(s) to update
?
UPDATE mytable SET a = 5, b = 3, c = 1 WHERE a > 0;
UPDATE products SET price = price * 1.10;
可以更新所有记录,也可以更新某条记录,取决于where条件。
可以更新多个字段。
如果没有记录满足where条件,不报错。
?
查:select
时间: 2024-10-12 14:09:46