发布网友 发布时间:2022-04-07 20:30
共2个回答
懂视网 时间:2022-04-08 00:52
school=# dn+
List of schemas
Name | Owner | Access privileges | Description
--------+----------+----------------------+------------------------
public | postgres | postgres=UC/postgres+| standard public schema
| | =UC/postgres |
(1 row)
语法:
school=# h create schema
Command: CREATE SCHEMA
Description: define a new schema
Syntax:
CREATE SCHEMA schema_name [ AUTHORIZATION user_name ] [ schema_element [ ... ] ]
CREATE SCHEMA AUTHORIZATION user_name [ schema_element [ ... ] ]
CREATE SCHEMA IF NOT EXISTS schema_name [ AUTHORIZATION user_name ]
CREATE SCHEMA IF NOT EXISTS AUTHORIZATION user_name
参数:
schema_name
模式名称,缺省使用user_name,且不能以pg_开头。
user_name
模式属于的用户,缺省为执行命令的用户。
schema_element
一条SQL语句,即创建模式后,在该模式下创建一个数据库对象。当前支持的子句有CREATE
TABLE, CREATE VIEW, CREATE INDEX, CREATE SEQUENCE, CREATE TRIGGER and GRANT。
IF NOT EXISTS
如果模式已存在,使用该选项不会抛出错误。使用此选项不能使用schema_element子句。
示例
create schema schema_test authorization test1 create table tbl_test(a int) create view view_test as select * from tbl_test;
访问模式下数据库对象在模式和数据库对象之间加一个句点即可
school=# select * from schema_test.tbl_test ; a --- (0 rows) school=# select * from schema_test.view_test ; a --- (0 rows)
语法:
school=# h alter schema
Command: ALTER SCHEMA
Description: change the definition of a schema
Syntax:
ALTER SCHEMA name RENAME TO new_name
ALTER SCHEMA name OWNER TO new_owner
参数:
name
模式名称
new_name
模式新的名称,同样新名称也不能以pg_开头
new_owner
模式新用户名称
示例
school=# alter schema schema_test owner to postgres ; ALTER SCHEMA school=# alter schema schema_test rename to test; ALTER SCHEMA school=# dn+ List of schemas Name | Owner | Access privileges | Description --------+----------+----------------------+------------------------ public | postgres | postgres=UC/postgres+| standard public schema | | =UC/postgres | test | postgres | | (2 rows)
语法:
school=# h drop schema
Command: DROP SCHEMA
Description: remove a schema
Syntax:
DROP SCHEMA [ IF EXISTS ] name [, ...] [ CASCADE | RESTRICT ]
参数:
IF EXISTS
如果模式不存在,不会抛出错误。
name
模式名称。
CASCADE
自动删除该模式下数据库对象。
RESTRICT
如果该模式下还存在数据库对象,则不允许删除该模式,RESTRICT为缺省值。
示例:
school=# drop schema test; ERROR: cannot drop schema test because other objects depend on it DETAIL: table test.tbl_test depends on schema test view test.view_test depends on schema test HINT: Use DROP ... CASCADE to drop the dependent objects too.
school=# drop schema test cascade; NOTICE: drop cascades to 2 other objects DETAIL: drop cascades to table test.tbl_test drop cascades to view test.view_test DROP SCHEMA
postgresql模式创建、修改、删除
标签:
热心网友 时间:2022-04-07 22:00
先在本机安装PostgreSQL数据库,然后在开始菜单中找到该程序,双击并打开该数据库。