1. 创建表
omm-# CREATE TABLE products
omm-# ( product_id integer,
omm(# product_name char(30),
omm(# ) ; category char(20)
omm(# ;
CREATE TABLE
2. 按带列名和不带列名的方式依次插入一条记录
omm=# INSERT INTO products (product_id, product_name, category) VALUES (1502, 'olympus camera','electrncs');
INSERT 0 1
omm=# INSERT INTO products VALUES (1601, 'lamaze','toys');
INSERT 0 1
3. 批量插入多条记录
omm=# INSERT INTO products (product_id, product_name, category) VALUES
omm-# (1700, 'wait interface', 'Books'),
omm-# (1666, 'harry potter','toys');
INSERT 0 2
omm=#
omm=#
omm=#
4. 查询记录数量和所有记录信息
omm=# select count(*) from products;
count
-------
4
(1 row)
omm=# select * from products;
product_id | product_name | category
------------+--------------------------------+----------------------
1502 | olympus camera | electrncs
1601 | lamaze | toys
1700 | wait interface | Books
1666 | harry potter | toys
(4 rows)
5. 查询category 并按category 升序排列
omm=# select category from products order by category;
category
----------------------
Books
electrncs
toys
toys
(4 rows)
6.查询category 为toys的记录
omm=# select * from products where category = 'toys';
product_id | product_name | category
------------+--------------------------------+----------------------
1601 | lamaze | toys
1666 | harry potter | toys
(2 rows)
7.删除表
omm=# drop table products;
DROP TABLE




