Search code examples
sqldatabasenumeric

How to make an employee wage restriction?


I have a database with an employee table. This table has the attributes: name, id, adress and salary.

I need to restrict the salary of employees between US $ 5000 to US $ 10,000. How can I implement this restriction?

My attempt was to define the data type of the salary attribute as:

      NUMERIC (5000, 10000)

However when I went to search the sql documentation I saw that NUMERIC (p, s) means p: precision s: scale


Solution

  • Try the check constraint when you create the table:

    salary NUMERIC 
    CONSTRAINT salary_range
        CHECK(salary >= 5000 and salary <= 10000)