postgresql命令操作
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了postgresql命令操作,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1389字,纯文字阅读大概需要2分钟。
内容图文
![postgresql命令操作](/upload/InfoBanner/zyjiaocheng/914/4aa8fb91f04945ee93d182cb33281dda.jpg)
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.
内容总结
以上是互联网集市为您收集整理的postgresql命令操作全部内容,希望文章能够帮你解决postgresql命令操作所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。