6.1. 插入数据
create table
CREATE TABLE products ( product_no integer, name text, price numeric );
INSERT INTO products VALUES (1, 'Cheese', 9.99); 上述语法的缺点是你必须知道表中字段的顺序。 你也可以明确地列出字段以避免这个问题。比如, 下面的两条命令都和上面的那条命令效果相同: INSERT INTO products (product_no, name, price) VALUES (1, 'Cheese', 9.99); INSERT INTO products (name, price, product_no) VALUES ('Cheese', 9.99, 1);
你可以在一条命令中插入多行(oracle不行!!!):
INSERT INTO products (product_no, name, price) VALUES (1, 'Cheese', 9.99), (2, 'Bread', 1.99), (3, 'Milk', 2.99);
6.2. 更新数据
UPDATE products SET price = 10 WHERE price = 5;
6.3. 删除数据
DELETE FROM products WHERE price = 10;
如果你只是写:
DELETE FROM products;
那么表中所有行都会被删除!程序员一定要注意。
可以使用计算:sELECT 3 * 4;
果选择列表里的表达式返回变化的结果,那么这个东西就更有用了。比如, 你可以用这个方法调用函数:
SELECT random();