当前位置:网站首页>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:数据定义语言,主要用于创建,删除,修改表,索引等
边栏推荐
- C#大型互联网平台管理框架源码:基于ASP.NET MVC+EF6+Bootstrap开发,支持多数据库
- 将vim与系统剪贴板的交互使用
- SQL Server (design database--stored procedure--trigger)
- 小程序毕设作品之微信美食菜谱小程序毕业设计成品(5)任务书
- 【SeaTunnel】从一个数据集成组件演化成企业级的服务
- ROS2初级知识(8):Launching启动多节点
- PHP算法之有效的括号
- perspectiveTransform warpPerspective getPerspectiveTransform findHomography
- 从0到1:图文投票小程序设计与研发笔记
- How to add a game character to a UE4 scene
猜你喜欢

Prufer序列

D - Linear Probing- 并查集
Background project Express-Mysql-Vue3-TS-Pinia page layout-sidebar menu

y84.第四章 Prometheus大厂监控体系及实战 -- prometheus告警机制进阶(十五)

y84. Chapter 4 Prometheus Factory Monitoring System and Actual Combat -- Advanced Prometheus Alarm Mechanism (15)

如何给 UE4 场景添加游戏角色

Small application project works WeChat stadium booking applet graduation design of the finished product (1) the development profile

PHP算法之电话号码的字母组合

复现gallerycms字符长度限制短域名绕过

Wechat Gymnasium Reservation Mini Program Graduation Design Finished Work Mini Program Graduation Design Finished Product (2) Mini Program Function
随机推荐
解决yolov5训练时出现:“AssertionError: train: No labels in VOCData/dataSet_path/train.cache. Can not train ”
使用Jenkins做持续集成,这个知识点必须要掌握
Quarantine and downgrade
ROS2初级知识(8):Launching启动多节点
JS prototype hasOwnProperty in 加方法 原型终点 继承 重写父类方法
Use Jenkins for continuous integration, this knowledge point must be mastered
prim生成树
毕业作业
Graph Theory - Strongly Connected Component Condensation + Topological Sort
论文解读(GSAT)《Interpretable and Generalizable Graph Learning via Stochastic Attention Mechanism》
深度学习Course2第二周Optimization Algorithms习题整理
B. Difference Array--Codeforces Round #808 (Div. 1)
From 0 to 100: Notes on the Development of Enrollment Registration Mini Programs
系统可用性:SRE口中的3个9,4个9...到底是个什么东西?
Go 微服务开发框架DMicro的设计思路
String - Trie
解决 win10 下 ISE14.7的 iMPACT 崩溃问题 - FPGA 笔记
基于JAX的激活函数、softmax函数和交叉熵函数
img 响应式图片的实现(含srcset属性、sizes属性的使用方法,设备像素比详解)
欧拉路径与欧拉回路