当前位置:网站首页>PostgreSQL Basics--Common Commands
PostgreSQL Basics--Common Commands
2022-08-01 23:07:00 【Rosita.】
Table of Contents
Common commands:
1. View all tables in the database: \d
2. View the definition of a table: \d table name
3. List all databases: \l
4. Switch to the specified database: \c database name
5. Exit: \q
PgSql basic syntax:
1. Create a table: create table table name (field 1 type primary key ,...);
2. Drop table: drop table name;
3. Insert statement: insert into table name values(value 1,...);
4. Update statement: update table name set field = "";
5. Delete statement: delete from table name;
6. Query all data statement: select * from table name
7. Sort (with select): Ascending: order by field
Descending: order by field desc
8. Group query (used with select and aggregation functions): group by
#Group by age: select age,count(*) from student group by age;
9. Multi-table joint query
Pay attention to giving each table an alias, where is the relationship between multiple tables
select a.student_name,b.class_name from student a, class b where a.id = b.id;
10.insert into ...select statement (insert data from one table into another table)
#student table structure
create table student(id serial primary key, student_name varchar(32), age int,class_id int);
#class table structure
create table class(id int, class_name varchar(32) primary key);
insert into student values(1,'Zhang San',19,1);
#Auto-increment data insertion (id is not 0):
insert into student select max(id+1),'Li Si',18,2 from student;
#Insert class data
insert into class select class_id,'third grade' from student where student_name = 'Zhangsan';
11 Cleanup table
truncate table table name;
12. Modify the field name:
alter table table name rename column field name to new field name
13 Modify table name:
alter table table name rename to new table name;
14 Delete fields:
alter table table name alter field name drop not null;
Extended:
SQL commands are generally divided into DQL, DML, DDL
DQL: Data query statement
DML: data manipulation language, mainly insert, update, delete data
DDL: Data Definition Language, mainly used to create, delete, modify tables, indexes, etc.
边栏推荐
- Quarantine and downgrade
- 小程序毕设作品之微信体育馆预约小程序毕业设计成品(1)开发概要
- PostgreSQL 基础--常用命令
- How to use pywinauto and pyautogui to link the anime lady and sister please go home
- 【数据分析03】
- excel remove all carriage return from a cell
- 系统可用性:SRE口中的3个9,4个9...到底是个什么东西?
- 添加大量元素时使用 DocumentFragments
- 牛客多校4 A.Task Computing 思维
- String - Trie
猜你喜欢

小程序毕设作品之微信体育馆预约小程序毕业设计成品(4)开题报告

还在纠结报表工具的选型么?来看看这个

毫秒级!千万人脸库快速比对,上亿商品图片检索,背后的极速检索用了什么神器?

小程序毕设作品之微信体育馆预约小程序毕业设计成品(1)开发概要

How to add a game character to a UE4 scene

APP专项测试:流量测试

请问什么是 CICD

xctf attack and defense world web master advanced area web2

03. GO language variable definition, function

小程序毕设作品之微信美食菜谱小程序毕业设计成品(6)开题答辩PPT
随机推荐
从0到1:图文投票小程序设计与研发笔记
华为无线设备配置全局双链路冷备份(AC全局配置方式)
1391D. 505 状压dp
Go 微服务开发框架DMicro的设计思路
从0到100:招生报名小程序开发笔记
IDEA入门看这一篇就够了
Create virtual environments with virtualenv and Virtualenvwrapper virtual environment management tools
(翻译)按钮的对比色引导用户操作的方式
Codeforces CodeTON Round 2 (Div. 1 + Div. 2, Rated, Prizes!) A-D 题解
excel vertical to horizontal
下载安装 vscode(含汉化、插件的推荐和安装)
数据库表设计规则
检查点是否在矩形内
得物客服热线的演进之路
Codeforces CodeTON Round 2 (Div. 1 + Div. 2, Rated, Prizes!) A-D Solution
测试岗月薪5-9k,如何实现涨薪到25k?
C语言——分支语句和循环语句
Is TCP reliable?Why?
bat 之 特殊字符&转义
加载字体时避免隐藏文本