Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
UNIQUE
NOT NULL
CHECK
22. CHECK - complex conditions
DEFAULT
Summary

Instruction

Great! Now, you should know that the logical conditions after the CHECK constraint can be complex. Take a look at the example below:

price decimal(5,2) CHECK (price > 0.00 and price < 800.00)

As you can see, we can join more than one condition to make bigger logical statements.

Exercise

Fill the template we prepared for you so that the column hours has a constraint: greater than 0 and lower than 999.

Stuck? Here's a hint!

Type

CREATE TABLE video_game (
  id IDENTITY PRIMARY KEY,
  name varchar(32) UNIQUE NOT NULL,
  genre varchar(32) NOT NULL,
  studio varchar(32),
  multiplayer boolean,
  hours int check (hours > 0 and hours < 999),
  price decimal(5, 2)
);