标签:varchar products price 命令 testdb 操作 postgresql select name
1.连接数据库
psql -h Server -p Port -U Username DatabaseName
2.创建数据库
postgres=# create database testdb;
3.查看数据库
postgres=# \l
4.删除数据库
postgres=# drop database testdb;
5.进入数据库
postgres=# \c testdb;
6.列出当前库所有表
testdb=# \dt
7.创建表
testdb=# create table account(
testdb(# user_id serial primary key,
testdb(# username varchar(50) unique not null,
testdb(# password varchar(50) not null);
create table products (
testdb(# product_no integer,
testdb(# name varchar(20),
testdb(# price numeric);
8.删除表
testdb=# drop table account;
9.创建模式
testdb=# CREATE SCHEMA myschema;
10.指定模式创建表
create table myschema.mytable(
user_id serial primary key,
username varchar(50) unique not null,
password varchar(50) not null);
11.删除模式里的对象
drop schema myschema CASCADE;
12.删除模式
drop schema myschema
13.插入数据
testdb=# insert into products values (1, 'chiness', 9.99);
14.查询数据
testdb=# select * from products;
15.更新数据
testdb=# update products set name = 'hyh' where product_no = 1;
16.删除表数据
testdb=# delete from products where name = 'hyh'; 字符串必须单引号
17.order by 升序,降序排列
testdb=# select from products order by price asc;
testdb=# select from products order by price desc;
18.order by 多列排序
select * from products order by price,product_no asc;
19.group by分组
testdb=# select name, sum(price) from products group by name;
按名字分组统计每个名字下的价格总额
20.
标签:varchar,products,price,命令,testdb,操作,postgresql,select,name 来源: https://blog.51cto.com/haoyonghui/2376807
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。