码迷,mamicode.com
首页 > 数据库 > 详细

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

时间:2016-04-18 18:47:21      阅读:209      评论:0      收藏:0      [点我收藏+]

标签:

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

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

标签:

原文地址:http://www.cnblogs.com/songlihong/p/5405199.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!