当前位置:网站首页>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.
边栏推荐
- PAM Palindromic Automata
- 从0到100:招生报名小程序开发笔记
- PostgreSQL 基础--常用命令
- leetcode刷题
- Chapter 11 Working with Dates and Times
- What is CICD excuse me
- Additional Features for Scripting
- CAKE:一个用于多视图知识图谱补全的可扩展性常识感知框架
- When solving yolov5 training: "AssertionError: train: No labels in VOCData/dataSet_path/train.cache. Can not train"
- PHP算法之有效的括号
猜你喜欢

【参营经历贴】2022网安夏令营

TCP 可靠吗?为什么?

13、学习MySQL 分组

系统可用性:SRE口中的3个9,4个9...到底是个什么东西?

leetcode刷题

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

Is TCP reliable?Why?

APP专项测试:流量测试

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

Small application project works WeChat stadium booking applet graduation design of the finished product (1) the development profile
随机推荐
三、mysql 存储引擎-建库建表操作
Go 微服务开发框架DMicro的设计思路
Codeforces CodeTON Round 2 (Div. 1 + Div. 2, Rated, Prizes!) A-D Solution
CAKE:一个用于多视图知识图谱补全的可扩展性常识感知框架
软技能之UML图
excel edit a cell without double clicking
程序员如何优雅地解决线上问题?
小程序毕设作品之微信体育馆预约小程序毕业设计成品(1)开发概要
bat 之 特殊字符&转义
【数据分析03】
毫秒级!千万人脸库快速比对,上亿商品图片检索,背后的极速检索用了什么神器?
excel remove all carriage return from a cell
ping no reply
How to add a game character to a UE4 scene
xctf attack and defense world web master advanced area webshell
数据库表设计规则
联邦学习入门
关于ETL的两种架构(ETL架构和ELT架构)
Is TCP reliable?Why?
PHP算法之电话号码的字母组合