当前位置:网站首页>PG Basics - logical structure management (1)
PG Basics - logical structure management (1)
2022-06-29 13:35:00 【51CTO】
database
Create database
CREATE DATABASE name
[
[ WITH
]
[ OWNER
[
=
] user_name
] Used to specify which user the new database belongs to , If it is not specified, the user who is currently executing the command
[ TEMPLATE
[
=
] template
] Specify template library
[ ENCODING
[
=
] encoding
] Specify character encoding
[ LC_COLLATE
[
=
] lc_collate
]
[ LC_CTYPE
[
=
] lc_ctype
]
[ TABLESPACE
[
=
] tablespace_name
] Specify the associated tablespace
[ ALLOW_CONNECTIONS
[
=
] allowconn
]
[ CONNECTION
LIMIT
[
=
] connlimit
] Specify acceptable concurrent connections , Default
-
1 Don't limit
[ IS_TEMPLATE
[
=
] istemplate
]
]
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
modify the database
alter database osdbadb connection
limit
10
;
alter database osdbadb rename to tesetdb01
;
alter database tesetdb01 owner to cjr
;
alter database testdb01
set tablespace new_tablespace
;
alter database tesedb01
set enable_indexscan TO off
;
alter database tesetdb01 reset all
;
alter database tesetdb reset enable_indexscan
;
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
Delete database
Pattern
Different schemas can have tables with the same name , Functions and other objects do not conflict , As long as you have authority , Objects of various patterns can call each other . stay PG in , You cannot access objects in different databases at the same time , Objects that can access multiple schemas in this database at the same time .
To create or access objects in a schema , Need to write a modified name , Schema name + Table name
schema_name.table_name
Users cannot access objects in the schema that do not belong to them , To access such an object , The owner of the schema must give them uasge jurisdiction . By default, everyone is public Both modes have create and USAGE jurisdiction , That is to say, all users who can connect to the specified database are allowed to create objects here . You can reclaim this permission
revoke create on schema public from PUBLIC ;
the second PUBLIC All users .
surface
Single primary key table
Compound primary key table
You need to use the syntax of a constraint clause
Unique constraint
Form creation
create table baby (like test003); But there is no copy constraint ,
Need to add INCLUDE keyword
create table baby1 (like test003 including all);
create table baby2 as select * from test003 with no data;
A temporary table
Session level temporary table , Another transaction level temporary table .
Session level temporary table
Transaction level temporary tables
Session level temporary table , Another transaction level temporary table .
create TEMPORARY table tmp_t1(id int primary key,note text); Session temporary table
create TEMPORARY table tmp_t2(id int primary key,note text) on commit delete rows; Transaction commit data disappears
create TEMPORARY table tmp_t2(id int primary key,note text) on commit PRESERVE ROWS; The data is stored throughout the session
create TEMPORARY table tmp_t2(id int primary key,note text) on commit drop; The transaction commit table disappears
UNLOGGED surface
Don't record wal journal , Abnormal downtime recovery is not possible , Normal shutdown does not affect
create unlogged table unlogged1(id int primary key,t text);
The default value is DEFAULT
upadte student set age=DEFAULT where no=2;
The default value is an expression , It will be calculated when inserting the default value , Instead of creating tables
Modify the default alter table student alter column age set default 15;
Delete default alter table student alter column age drop default;
constraint
Check constraint
Reference constraint name
Writing of constraints
The third constraint is not attached to a field , Instead, it appears as a separate line in a comma separated list .
Or so
Unique constraint
Non empty constraint
not null Decorate the field
Foreign key constraints
Add constraints
Delete constraints
Delete a non empty constraint. A non empty constraint has no name , You can delete
alter table student alter column student_name drop not null;
Primary key constraint
Primary keys can be created later
alter table books add constraint pk_book_book_no primary key(book_no);
Table related operations
Add fields alter table class add column class_teacher varchar(40);
Delete field alter tableclass drop column class_teacher;
Rename field alter table books rename column book_no to book_id;
rename table alter table books rename to book;
边栏推荐
- Aurora · Huffman tree generation (segment tree structure non pointer) (imitating adjacency table)
- Is it safe to open an account online?
- System. Currenttimemillis() and system Nanotime() which is faster? Most people get the wrong answer!
- 【云驻共创】通过Rust语言计算加速技术突破图片识别性能瓶颈
- 服务器监控netdata面板配置邮件服务
- C语言内存函数
- 3个最佳实践助力企业改善供应链安全
- [cloud resident co creation] industrial wisdom "brain", a new acceleration script for old factories
- Qitai observation: professional elites must step on the huge pit of entrepreneurship - learning effect pit
- 安装terraform-ovirt插件为ovirt提供自动化管理
猜你喜欢

Force buckle: merging two ordered linked lists

Rslo: self supervised lidar odometer (real time + high precision, icra2022)

想做个答题类的微信小游戏?读这篇文章就够了

System. Currenttimemillis() and system Nanotime() which is faster? Most people get the wrong answer!

sqlite3入门

Server monitoring netdata panel configuring mail service

win32版俄罗斯方块(学习MFC必不可少)

Leetcode game 299

What if the excel table exported from the repair record is too large?

mysql调优
随机推荐
【云驻共创】通过Rust语言计算加速技术突破图片识别性能瓶颈
YOLO系列梳理(九)初尝新鲜出炉的YOLOv6
Horizon development board configuration network segment
【毕业季】这四年一路走来都很值得——老学长の忠告
AOSP ~ logcat persistence
Summary of common MySQL statements and commands
韩国AI团队抄袭震动学界!1个导师带51个学生,还是抄袭惯犯
服务器监控netdata面板配置邮件服务
Netdata data data persistence configuration
Server monitoring netdata panel configuring mail service
如何让 Dapper 支持 DateOnly 类型
leetcode 903. Effective arrangement of Di sequences
CVPR2022 | 长期行动预期的Future Transformer
LeCun用62页论文公布未来十年研究计划:AI自主智能
商品搜索引擎—推荐系统设计
从零搭建Pytorch模型教程(四)编写训练过程--参数解析
Evaluation of powerful and excellent document management software: image management, book management and document management
Redis deletion policy and eviction algorithm
Windbg调试工具介绍
mybaits入门(含实例教程和源码)