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

Instruction

As you can see, the database protects the columns from any invalid values, even when updating the row. The column price must be greater than 0, so when you try to update any row and provide a number lower than 0, the database will not allow it. Good news.

Exercise

It's your turn to create the table with CHECKs! Use the template we provided and complete the instruction: the hours and price should both be greater than zero. Each time remember to put the CHECK keyword after the column type, followed by the logical condition.

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,
    price decimal(5,2) check price > 0
);