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

Instruction

Well, the update failed because the new value for the column price didn't meet the criterion, just as we could expect.

Exercise

Let's leave the game community for a while and do a little practice. Create a table salary with the following columns:

  • employee_id - a unique integer number,
  • monthly - a decimal of up to 10 digits with 2 digits after the decimal point,
  • annual - a decimal of up to 10 digits with 2 digits after the decimal point.
Add the following CHECK constraint: the annual field must equal the monthly field times 12.

Stuck? Here's a hint!

Type

CREATE TABLE salary (
  employee_id int UNIQUE,
  monthly decimal(10,2),
  annual decimal(10,  2),
  CHECK (monthly * 12 = annual)
);