The SQL statement may be employed to specify a schema as the default one for the current connection to the NuoSQL client.

句法

用 schema_name
schema_name

架构的名称设置为默认值。

描述

NOODB数据库可能具有多个模式,每个模式包含表,视图,索引等。 When executing an SQL statement, you might specify a table within a schema by naming the schema and then the table, separated by a dot (e.g., bookstore.books). However, if you intend to execute several SQL statements involving tables and other objects within a schema, you can first execute the statement to set the default schema. 然后,您只需要在下面的每个SQL中指定表名。 To execute an SQL statement on another schema, you would either execute the statement again for that schema, or utilize the emphatic schema.table method within the SQL statements.

Please note that when executing the statement, if the schema doesn’存在T,SQL语句仍然接受架构给出的值,假设它是正确的,并且您将很快创建对象。 If you then create an object such as a table, before ending the session or before executing the statement again for another schema, the 创建架构 声明将在幕后执行。

例子

Suppose you have a database which contains a few schemas, one of which is called sports. 它包含与运动队有关的信息表。 进一步假设您即将执行几个SQL语句以插入和从此模式中选择数据。 Therefore, you decide to make sports the default schema. 通过这种方法,表名赢了’t have to be qualified by the schema_name.

To do this, you need only execute the statement and specify the schema name, sports. After that, the sports schema will be assumed for each SQL statement in which you don’t include a schema name as a prefix of the table name (e.g., sports.baseball).

如果要创建架构以准备创建表和其他对象,但尚未准备好创建它们,则应使用 创建架构 statement.

用 sports;

选择 * FROM hockey
WHERE number > 40;

 ID  NUMBER       NAME      POSITION   TEAM
 --- ------- -------------- --------- ------
  8    64    LANE MACDERMID  Forward  Bruins
  9    63    BRAD MARCHAND   Forward  Bruins
 12    91    MARC SAVARD     Forward  Bruins

 选择 title, author FROM bookstore.books
 WHERE author LIKE '%Greene'
 LIMIT 2;

       TITLE          AUTHOR
 ----------------- -------------

 The Comedians     Graham Greene
 End of the Affair Graham Greene

Consider another situation: Suppose you execute the statement and specify a schema that doesn’t exist. You won’t收到错误消息,并获得新的架构’t be created yet. 但是,如果在将该未知模式设置为默认值的情况下创建表或其他对象,则系统将创建一个架构以保存对象。

用 birdwatchers;

表演 SCHEMAS
    Found 4 schemas
        BOOKSTORE
        SPORTS
        SYSTEM
        用R

CREATE TABLE birds
(bird_species STRING, common_name STRING);

表演 SCHEMAS;
    Found 5 schemas
        BIRDWATCHERS (current)
        BOOKSTORE
        SPORTS
        SYSTEM
        用R

Notice in the examples here, no error message was returned by specifying the birdwatchers schema, even though it didn’t exist. Notice also that the birdwatchers schema didn’t show in the results of 表演 SCHEMAS statement until a table was created.