一. highgo使用
1. 数据库创建、删除等常用命令
1.1 使用 CREATE DATABASE SQL 语句来创建。
[root@hgdb ~]# su - highgo
[highgo@hgdb ~]$ psql
highgo=# create database dbname; #创建数据库
highgo=# drop database dbname; #删除数据库
1.2 表的创建与重命名
highgo=# create table tbl_test (id int, info text, c_time timestamp); #创建表
highgo=# ALTER TABLE zhu RENAME TO zhufei; 重命名表
highgo=# drop table zhufei; 删除表
highgo=# create table test (id int); #创建表
highgo=# insert into test values(1),(2),(3); 插入数据
highgo=# select * from test; 查看表数据
highgo=# update test set a =4 where a=1; 更新表数据
highgo=# delete from test where a =2; 删除表数据
1.3 多表联查
- (refer to: https://www.cnblogs.com/thunisoft-zxt/p/6611051.html)
highgo=# select * from table_name1 inner join table_name2 on table_name.volume= table_name2.volume; #多表联查 内连接
1.4 使用 createdb 命令来创建。
[root@hgdb ~]# su - highgo
[highgo@hgdb ~]$ createdb mydb #创建数据库
[highgo@hgdb ~]$ dropdb mydb #删除数据库
1.5 对表空间进行创建、修改、删除。
- (refer to:https://blog.csdn.net/puyeza46/article/details/88286569)
highgo=# create tablespace tbs_test owner highgo location '/usr/local/pgdata';#创建
highgo=# alter tablespace tbs_test rename to tbs_tt; #修改
highgo=# drop tablespace tbs_test; #删除
1.6 索引的创建、修改、查看、删除
highgo=# select * from pg_indexes where tablename='z1'; #查看索引
highgo=# create index tbl_bb_index on tbl_bb(id,name);#注:tbl_bb 位表名称, tbl_bb_index 为创建的索引名称, id 和 name 为 表里的字段删除索引
highgo=# drop index h; #删除索引, h是创建的索引
highgo=# alter index h rename to hh; #修改索引
1.7 视图的创建、修改、删除
highgo=# CREATE VIEW view_name AS SELECT volume1,volume2 FROM table_name WHERE [condition]; #创建视图
highgo=# SELECT * FROM f2_view ; #查询数据
2 | 3
2 |