SQL-J Language Reference
Page 14 of 121

CREATE SCHEMA statement

A schema is a way to logically group objects in a single collection and provide a unique namespace for objects.

Syntax

CREATE SCHEMA SchemaName

The CREATE SCHEMA statement is used to create a schema. Schema names must be unique within the database.

You must create a schema with a CREATE SCHEMA statement before referring to it, unless the schema is the APP or SYS schema.

CREATE SCHEMA Examples

-- Create a schema for hotel-related tables
CREATE SCHEMA Hotels

-- Create a schema for airline-related tables
CREATE SCHEMA Flights

-- Create a table called "Availability" in each schema
CREATE TABLE Flights.Availability
    (flight_id CHAR(6),
    segment_number INT,
    flight_date DATE,
    economy_seats_taken INT,
    business_seats_taken INT,
    firstclass_seats_taken INT,
    CONSTRAINT Flight_Availability_PK PRIMARY KEY
        (flight_id, segment_number, flight_date))

CREATE TABLE Hotels.Availability
(    hotel_id INT,
    booking_date DATE,
    rooms_taken INT,
    CONSTRAINT HotelAvailability_PK PRIMARY KEY
        (hotel_id, booking_date))