CREATE SCHEMA 中文man页面

系统
CREATE SCHEMA 将在当前数据库里输入一个新的模式。 该模式名将在当前数据库里现存的所有模式名中唯一。

NAME

CREATE SCHEMA - 定义一个新的模式

SYNOPSIS

CREATE SCHEMA schemaname [ AUTHORIZATION username ] [ schema_element [ ... ] ]
CREATE SCHEMA AUTHORIZATION username [ schema_element [ ... ] ]

DESCRIPTION 描述

CREATE SCHEMA 将在当前数据库里输入一个新的模式。 该模式名将在当前数据库里现存的所有模式名中唯一。


 模式实际上是一个名字空间: 它包含命名对象(表,数据类型,函数和操作符)这些名字可以和其它模式里存在的其它对象重名。 命名对象要么是通过用模式名作为前缀"修饰"这些它们的名字进行访问, 要么是通过设置一个搜索路径包含所需要的模式。 无修饰的对象都是在当前模式中创建的(在搜索路径最前面的;可以用函数 current_schema 来判断)。


 另外,CREATE SCHEMA 可以包括在新模式中创建对象的子命令。 这些子命令和那些在创建完模式后发出的命令没有任何区别,只不过是如果使用了 AUTHORIZATION 子句, 那么所有创建的对象都将被该用户拥有。  

PARAMETERS 参数

schemaname

 要创建的模式名字。如果省略,则使用用户名作为模式名。
username

 将拥有该模式的用户名。如果省略,缺省为执行该命令的用户名。 只有超级用户才能创建不属于自己的模式。
schema_element

 一个 SQL 语句,定义一个要在模式里创建的对象。 目前,只有 CREATE TABLE,CREATE VIEW, 和 GRANT 是在 CREATE SCHEMA 里面可以接受的子句。 其它类型的对象可以在创建完模式之后的独立的命令里创建。

NOTES 注意


 要创建模式,调用该命令的用户必需在当前数据库上有 CREATE 权限。(当然,超级用户绕开这个检查。)  

EXAMPLES 例子


 创建一个模式:

CREATE SCHEMA myschema;


 为用户 joe 创建模式 --- 模式也会叫 joe:

CREATE SCHEMA AUTHORIZATION joe;


 创建一个模式并且在里面创建一个表:

CREATE SCHEMA hollywood
    CREATE TABLE films (title text, release date, awards text[])
    CREATE VIEW winners AS
        SELECT title, release FROM films WHERE awards IS NOT NULL;


 请注意上面的独立的子命令不是由分号结尾的。


 下面的命令是实现同样结果的等效语句:

CREATE SCHEMA hollywood;
CREATE TABLE hollywood.films (title text, release date, awards text[]);
CREATE VIEW hollywood.winners AS
    SELECT title, release FROM hollywood.films WHERE awards IS NOT NULL;

COMPATIBILITY 兼容性


 SQL 标准允许在 CREATE SCHEMA 里面有一个 DEFAULT CHARACTER SET 子句,以及比目前 PostgreSQL 可以接受的更多的子命令。


 SQL 标准声明在 CREATE SCHEMA 里的子命令可以以任意顺序出现。 目前 PostgreSQL  里的实现还不能处理所有子命令里需要提前引用的情况;有时候可能需要重排一下子命令的顺序以避免前向引用。


 在 SQL 标准里,模式的所有者总是拥有其中的所有对象。 PostgreSQL 允许模式包含非模式所有者所有的对象。 只有在模式所有者 CREATE 了自己的模式的权限给了其它人才可能出现。  

SEE ALSO 参见

ALTER SCHEMA [alter_schema(7)], DROP SCHEMA [drop_schema(l)]  

#p#

NAME

CREATE SCHEMA - define a new schema

SYNOPSIS

CREATE SCHEMA schemaname [ AUTHORIZATION username ] [ schema_element [ ... ] ]
CREATE SCHEMA AUTHORIZATION username [ schema_element [ ... ] ]

DESCRIPTION

CREATE SCHEMA will enter a new schema into the current database. The schema name must be distinct from the name of any existing schema in the current database.

A schema is essentially a namespace: it contains named objects (tables, data types, functions, and operators) whose names may duplicate those of other objects existing in other schemas. Named objects are accessed either by ``qualifying'' their names with the schema name as a prefix, or by setting a search path that includes the desired schema(s). Unqualified objects are created in the current schema (the one at the front of the search path, which can be determined with the function current_schema).

Optionally, CREATE SCHEMA can include subcommands to create objects within the new schema. The subcommands are treated essentially the same as separate commands issued after creating the schema, except that if the AUTHORIZATION clause is used, all the created objects will be owned by that user.  

PARAMETERS

schemaname
The name of a schema to be created. If this is omitted, the user name is used as the schema name.
username
The name of the user who will own the schema. If omitted, defaults to the user executing the command. Only superusers may create schemas owned by users other than themselves.
schema_element
An SQL statement defining an object to be created within the schema. Currently, only CREATE TABLE, CREATE VIEW, and GRANT are accepted as clauses within CREATE SCHEMA. Other kinds of objects may be created in separate commands after the schema is created.

NOTES

To create a schema, the invoking user must have CREATE privilege for the current database. (Of course, superusers bypass this check.)  

EXAMPLES

Create a schema:

CREATE SCHEMA myschema;

Create a schema for user joe; the schema will also be named joe:

CREATE SCHEMA AUTHORIZATION joe;

Create a schema and create a table and view within it:

CREATE SCHEMA hollywood
    CREATE TABLE films (title text, release date, awards text[])
    CREATE VIEW winners AS
        SELECT title, release FROM films WHERE awards IS NOT NULL;

Notice that the individual subcommands do not end with semicolons.

The following is an equivalent way of accomplishing the same result:

CREATE SCHEMA hollywood;
CREATE TABLE hollywood.films (title text, release date, awards text[]);
CREATE VIEW hollywood.winners AS
    SELECT title, release FROM hollywood.films WHERE awards IS NOT NULL;

COMPATIBILITY

The SQL standard allows a DEFAULT CHARACTER SET clause in CREATE SCHEMA, as well as more subcommand types than are presently accepted by PostgreSQL.

The SQL standard specifies that the subcommands in CREATE SCHEMA may appear in any order. The present PostgreSQL implementation does not handle all cases of forward references in subcommands; it may sometimes be necessary to reorder the subcommands to avoid forward references.

According to the SQL standard, the owner of a schema always owns all objects within it. PostgreSQL allows schemas to contain objects owned by users other than the schema owner. This can happen only if the schema owner grants the CREATE privilege on his schema to someone else.  

SEE ALSO

ALTER SCHEMA [alter_schema(7)], DROP SCHEMA [drop_schema(l)]

责任编辑:韩亚珊 来源: CMPP.net
相关推荐

2011-08-24 10:56:32

CREATE CONV中文man

2011-08-24 13:46:39

CREATE VIEW中文man

2011-08-24 13:43:09

CREATE USER中文man

2011-08-24 10:46:36

CREATE AGGR中文man

2011-08-24 13:36:25

CREATE TRIG中文man

2011-08-24 13:29:20

CREATE TABL中文man

2011-08-24 11:15:24

CREATE INDE中文man

2011-08-24 13:32:56

CREATE TABL中文man

2011-08-24 11:02:11

CREATE DOMA中文man

2011-08-24 11:05:36

CREATE FUNC中文man

2011-08-24 13:39:44

CREATE TYPE中文man

2011-08-24 10:59:19

CREATE DATA中文man

2011-08-24 11:18:53

CREATE LANG中文man

2011-08-24 11:10:17

CREATE GROU中文man

2011-08-24 11:23:20

CREATE OPER中文man

2011-08-24 11:31:47

CREATE RULE中文man

2011-08-24 13:26:19

CREATE SEQU中文man

2011-08-24 09:39:10

alter_schem中文man

2011-08-24 14:43:21

drop_schema中文man

2011-08-25 14:07:55

create_modu中文man
点赞
收藏

51CTO技术栈公众号