当前位置:网站首页>PostgreSQL 基础--常用命令
PostgreSQL 基础--常用命令
2022-08-01 23:01:00 【Rosita.】
目录
常用命令:
1.查看数据库所有表 : \d
2.查看某表的定义情况 : \d 表名
3.列出所有数据库: \l
4.切到指定数据库: \c 数据库名
5.退出: \q
PgSql基础语法:
1.创建表:crearte table 表名(字段1 类型 primary key ,...);
2.删除表:drop table name;
3.插入语句:insert into 表名 values(值1,...);
4.更新语句:update 表名 set 字段 = "";
5.删除语句:delete from 表名;
6.查询所有数据语句:select * from 表名
7.排序(配合select用):升序:order by 字段
降序:order by 字段 desc
8.分组查询(配合select和聚合函数用):group by
#按照学生年龄分组:select age,count(*) from student group by age;
9.多表联查
注意给每个表起别名,where多表的关联关系
select a.student_name,b.class_name from student a, class b where a.id = b.id;
10.insert into ...select语句(把数据从一张表插入另一张表)
#student表结构
create table student(id serial primary key, student_name varchar(32), age int,class_id int);
#class表结构
create table class(id int, class_name varchar(32) primary key);
insert into student values(1,'张三',19,1);
#自增数据插入(id不为0):
insert into student select max(id+1),'李四',18,2 from student;
#插入class数据
insert into class select class_id,'三年级' from student where student_name = '张三';
11清理表
truncate table 表名;
12.修改字段名:
alter table 表名 rename column 字段名 to 新字段名
13 修改表名:
alter table 表名 rename to 新表名;
14删除字段:
alter table 表名 alter 字段名 drop not null;
拓展:
SQL命令一般分DQL,DML,DDL
DQL:数据查询语句
DML:数据操纵语言,主要是插入,更新,删除数据
DDL:数据定义语言,主要用于创建,删除,修改表,索引等
边栏推荐
- 一种灵活的智能合约协作方式
- APP special test: traffic test
- Interpretation of the paper (GSAT) "Interpretable and Generalizable Graph Learning via Stochastic Attention Mechanism"
- 解决 win10 下 ISE14.7的 iMPACT 崩溃问题 - FPGA 笔记
- 毕业作业
- perspectiveTransform warpPerspective getPerspectiveTransform findHomography
- 【参营经历贴】2022网安夏令营
- 解决yolov5训练时出现:“AssertionError: train: No labels in VOCData/dataSet_path/train.cache. Can not train ”
- leetcode刷题
- 联邦学习在金融领域的发展和应用
猜你喜欢
2022 edition of MySQL tutorial, top collection good, take your time
下载安装 vscode(含汉化、插件的推荐和安装)
从0到1:图文投票小程序设计与研发笔记
【数据分析03】
Codeforces CodeTON Round 2 (Div. 1 + Div. 2, Rated, Prizes!) A-D 题解
npm包【详解】(内含npm包的开发、发布、安装、更新、搜索、卸载、查看、版本号更新规则、package.json详解等)
Background project Express-Mysql-Vue3-TS-Pinia page layout-sidebar menu
2022-08-01 第八组 曹雨 泛型 枚举
[深入研究4G/5G/6G专题-48]: 5G Link Adaption链路自适应-4-下行链路自适应DLLA-PDCCH信道
Go 微服务开发框架DMicro的设计思路
随机推荐
别看了,这就是你的题呀
下载安装 vscode(含汉化、插件的推荐和安装)
Still struggling with reporting tool selection?To take a look at this
03、GO语言变量定义、函数
npm包【详解】(内含npm包的开发、发布、安装、更新、搜索、卸载、查看、版本号更新规则、package.json详解等)
PHP算法之最接近的三数之和
SQL29 Calculate the average next day retention rate of users
数据库表设计规则
Small application project works WeChat stadium booking applet graduation design of the finished product (1) the development profile
PDF转Word有那么难吗?做一个文件转换器,都解决了
B. Difference Array--Codeforces Round #808 (Div. 1)
leetcode刷题
图论——强连通分量缩点+拓扑排序
解决 win10 下 ISE14.7的 iMPACT 崩溃问题 - FPGA 笔记
从0到100:招生报名小程序开发笔记
Deep learning Course2 first week Practical aspects of Deep Learning exercises
如何理解 new (...args: any[]) => any
华为无线设备配置双链路冷备份(AP指定配置方式)
excel split text into different rows
杭电多校3 1012. Two Permutations dp*