当前位置:网站首页>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.
边栏推荐
- APP专项测试:流量测试
- Chapter 19 Tips and Traps: Common Goofs for Novices
- 2022/7/31
- Calculate the distance between two points
- 03、GO语言变量定义、函数
- 程序员如何优雅地解决线上问题?
- Three, mysql storage engine - building database and table operation
- C#大型互联网平台管理框架源码:基于ASP.NET MVC+EF6+Bootstrap开发,支持多数据库
- 杭电多校3 1012. Two Permutations dp*
- APP special test: traffic test
猜你喜欢

Solve the port to take up

访问控制台中的选定节点

PHP算法之电话号码的字母组合
Background project Express-Mysql-Vue3-TS-Pinia page layout-sidebar menu

论文理解【RL - Exp Replay】—— Experience Replay with Likelihood-free Importance Weights

移动端人脸风格化技术的应用

xctf攻防世界 Web高手进阶区 webshell

软技能之UML图

From 0 to 1: Design and R&D Notes of Graphic Voting Mini Program

毫秒级!千万人脸库快速比对,上亿商品图片检索,背后的极速检索用了什么神器?
随机推荐
域名重定向工具 —— SwitchHosts 实用教程
美赞臣EDI 940仓库装运订单详解
测试岗月薪5-9k,如何实现涨薪到25k?
PHP算法之最接近的三数之和
excel remove all carriage return from a cell
如何给 UE4 场景添加游戏角色
CAKE:一个用于多视图知识图谱补全的可扩展性常识感知框架
y84.第四章 Prometheus大厂监控体系及实战 -- prometheus告警机制进阶(十五)
PostgreSQL 基础--常用命令
杭电多校3 1012. Two Permutations dp*
perspectiveTransform warpPerspective getPerspectiveTransform findHomography
SQL Server (design database--stored procedure--trigger)
How to use pywinauto and pyautogui to link the anime lady and sister please go home
编曲软件FL studio20.8中文版功能和作用
sys_kill系统调用
Mini Program Graduation Works WeChat Food Recipe Mini Program Graduation Design Finished Product (8) Graduation Design Thesis Template
牛客多校4 A.Task Computing 思维
xctf attack and defense world web master advanced area web2
选择合适的 DevOps 工具,从理解 DevOps 开始
计算两点之间的距离