Postgresql流水帐(第五天):增删查改

增: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:

  1. The name of the table and column to update
  2. The new value of the column
  3. 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

posted @ 2016-04-18 17:23  songlihong  阅读(278)  评论(0编辑  收藏  举报