標籤:
增: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
Postgresql流水帳(第五天):增刪查改