PostgresSQL(一)
Postgres基础
基础操作
数据库创建
# 创建数据库
postgres=# create database test;
\l 显示所有数据库
\c 连接指定数据库
不用断开连接 就可以连接到其他数据库
\c 可以连接其他数据库名字
删除数据库库 drop database test;
\q 断开连接的所有数据库
或者在pg里面点击
server -- discount server
2. Create and Delete Table
连接数据库test
\c test;
1.在SQL shell中 创建表单
test=# create table company(id int primary key not null , name text not null , age int not null ,address char(50) , salary real);
这里id 设置为primay key 因此值不能为空,
name text格式 不能为空
age 整数 不能为空
adress 字符串 50bites以内 可以为空
salary real 可以为空
/d describe 查看结构
现在我们再来创建一个表
emp_id 表示 employee 员工
现在\d 我们可以看见有2张表啦
2. 在pg4中 创建表单
添加column
constraint 约束 限制
最后删除数据库的话 我这里更倾向于使用SQL shell进行删除
删除表
首先要\c 连接到对应数据库 再输入:
drop table sudent;
/d 查看删除后的目录结构
至此,第四章看完
https://www.youtube.com/watch?v=4EOzwZ1kjRQ&list=PLk1kxccoEnNEtwGZW-3KAcAlhI_Guwh8x&index=4
posted on 2020-07-13 17:13 sunnywillow 阅读(398) 评论(0) 编辑 收藏 举报