1.Oracle的schema
一般而言,一个用户就对应一个schema,schema名一般等于用户名,作为该用户缺省的schema。
schema不能由用户创建,是在某个用户创建了第一个对象(表、视图等)之后才会创建一个schema,当且仅当该用户下存在对象的时候才会存在schema。oracle中的create schema语句不能创建schema:
CREATE SCHEMAPurpose:Use the CREATE SCHEMA to create multiple tables and views and perform multiple grants in a single transaction.
To execute a CREATE SCHEMA statement, Oracle executes each included statement. If all statements execute successfully, Oracle commits the transaction. If any statement results in an error, Oracle rolls back all the statements.
Note:This statement does not actually create a schema. Oracle automatically creates a schema when you create a user (see CREATE USER). This statement lets you populate your schema with tables and views and grant privileges on those objects without having to issue multiple SQL statements in multiple transactions.
简单来说就是在单个事务中创建多个表,视图等,和执行多个赋权。如果所有的语句都成功就提交事务,有一个不成功就回滚,但是create schema语句并不创建一个schema。
A schema is a collection of database objects (used by a user.).
schema是被一个用户使用的数据库对象的集合。
Schema objects are the logical structures that directly refer to the database’s data.
schema是直接关联数据库数据的逻辑结构。
A user is a name defined in the database that can connect to and access objects.
用户是在数据库中定义,能连接和获取数据库对象的名字。
Schemas and users help database administrators manage database security.
架构和用户帮助数据库管理员管理数据库安全。
总结起来就是,schema是一个数据库中某个用户拥有的所有对象(表,视图等)的集合,名称一般和用户名相同。
PostgreSQL的schema默认命名为public,如果不特别指定,PostgeSQL以public模式操纵各类数据库对象。
PostgreSQL可以在数据库中创建schema,语句为create schema "MySchema";
其和oracle的schema不同之处在于其名称,oracle的默认schema是和用户名同名的schema,而posgresql默认的是名为public的schema。