Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Primary keys – the basics
Single-column primary keys
Multi-column primary keys
NOT NULL
Review
25. Question 1

Instruction

Wow! We're pretty much done with this part of the course.

Let's summarize what we have learned so far:

  1. A single-column primary key is a NOT NULL column, whose value is unique for a given row. For instance:
    CREATE TABLE movie (
      id integer PRIMARY KEY,
      title varchar(64),
      year integer
    );
  2. A multi-column primary key is a group of NOT NULL columns, whose values constitute a unique combination for a given row. For instance:
    CREATE TABLE order_item (
      order_id integer,
      sequence integer,
      name varchar(32),
      quantity integer,
      PRIMARY KEY (order_id, sequence)
    );
  3. You can add a NOT NULL constraint to a column. A NOT NULL column must have a value other than NULL in every row. For instance:
    CREATE TABLE rpg_game (
      id int PRIMARY KEY,
      name varchar(32) NOT NULL,
      genre varchar(32)
    );

Before we let you go, we've got a short quiz! Are you ready?

Exercise

Let's get started with the review. Use the ERD diagram below to create the proper table:

LEAD

Stuck? Here's a hint!

Type:

CREATE TABLE book (
  isbn varchar(10) PRIMARY KEY,
  title varchar(128),
  author varchar(64),
  publishing_house varchar(64),
  genre varchar(64) NOT NULL
);