Example 1: Setting schema and catalog defaults to create a table
in a multischema database
In this example, user ELLINGSWORTH attaches to two databases: the
default database, personnel, and the multischema corporate_data
database with alias CORP. User ELLINGSWORTH attempts to create
a table in the corporate_data database, and receives an error
message because the default schema is ELLINGSWORTH, which has
not been created in the default catalog. User ELLINGSWORTH uses
SET SCHEMA and SET CATALOG statements to change the defaults to
catalog ADMINISTRATION and schema ACCOUNTING of the corporate_
data database.
Use the SHOW DATABASE statement to see the database settings.
SQL> ATTACH 'FILENAME personnel';
SQL> ATTACH 'ALIAS CORP FILENAME corporate_data';
SQL> SHOW SCHEMAS;
Schemas in database with filename personnel
No schemas found
Schemas in database CORP
"CORP.ADMINISTRATION".ACCOUNTING
"CORP.ADMINISTRATION".PERSONNEL
"CORP.ADMINISTRATION".RECRUITING
"CORP.RDB$CATALOG".RDB$SCHEMA
SQL> CREATE TABLE CORP.BUDGET (COL1 REAL);
%SQL-F-SCHNOTDEF, Schema "CORP.RDB$CATALOG".CORP is not defined
SQL> --
SQL> -- SQL interprets CORP as schema name, and there is no
SQL> -- CORP schema in the default database.
SQL> --
SQL> -- Add quotation marks to designate qualifier CORP as an alias,
SQL> -- not the schema name.
SQL> --
SQL> SET QUOTING RULES 'SQL92';
SQL> CREATE TABLE "CORP.BUDGET" (COL1 REAL);
%SQL-F-SCHNOTDEF, Schema "CORP.RDB$CATALOG".ELLINGSWORTH is not defined
SQL> --
SQL> -- The default schema in the database with alias CORP
SQL> -- is the user name ELLINGSWORTH, but there is no
SQL> -- schema named ELLINGSWORTH.
SQL> --
SQL> -- Set the default schema to ACCOUNTING, and qualify it
SQL> -- with a delimited identifier containing the alias CORP and
SQL> -- the catalog ADMINISTRATION. Now you can create the
SQL> -- table BUDGET within schema ACCOUNTING without qualifying
SQL> -- the table name.
SQL> --
SQL> SET SCHEMA '"CORP.ADMINISTRATION".ACCOUNTING';
SQL> CREATE TABLE BUDGET (COL1 REAL);
SQL> SHOW TABLES;
User tables in database with filename personnel
CANDIDATES
COLLEGES
.
.
.
User tables in database with alias CORP
"CORP.ADMINISTRATION".ACCOUNTING.BUDGET
.
.
.