4.1 Create a Table (BOOKS)

The BOOKS table contains a row for each book in the library. It includes columns of character and number types, a primary key, a unique constraint, and a check constraint.

  1. Right-click the connection name, and select Open SQL Worksheet.

  2. Enter the following statement:

    CREATE TABLE books (
       book_id VARCHAR2(20),
       title VARCHAR2(50)
          CONSTRAINT title_not_null NOT NULL,
       author_last_name VARCHAR2(30)
          CONSTRAINT last_name_not_null NOT NULL,
       author_first_name VARCHAR2(30),
       rating NUMBER,
       CONSTRAINT books_pk PRIMARY KEY (book_id),
       CONSTRAINT rating_1_to_10 CHECK (rating IS NULL OR
          (rating >= 1 and rating <= 10)),
       CONSTRAINT author_title_unique UNIQUE (author_last_name, title));
  3. Click the Run Statement icon.

    The following notification is displayed in the Script Output pane:

    Table BOOKS created.