Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
UNIQUE
NOT NULL
CHECK
DEFAULT
Summary
33. Revision #1

Instruction

Excellent! Now it's time for a little quiz. See for yourself how well you remember the information from this part. Are you ready?

Exercise

Create a table person based on the description below.

Each person has an id expressed as an integer number which is the primary key. They also have an obligatory ssn (social security number) of precisely 10 characters which is unique for each person.

They have a first_name of up to 255 characters and a last_name of up to 255 characters as well. Both of these fields must have a defined value. Some people also have a middle_name of up to 255 characters, but this isn't obligatory.

Each person has a certain salary which must always be greater than 0. The salary can be up to 10 digits long, of which 2 digits are found behind the decimal point. If no salary is specified, then 5000.00 is inserted by default.

Stuck? Here's a hint!

Type

CREATE TABLE person (
  id int PRIMARY KEY,
  ssn char(10) UNIQUE NOT NULL,
  first_name varchar(255) NOT NULL,
  middle_name varchar(255) NULL,
  last_name varchar(255) NOT NULL,
  salary decimal(10, 2) DEFAULT 5000.00 CHECK salary > 0
);