create table sallaary(
E_ID number (10) , bank_type varchar(10), creditcardnumber number(12) primary key , bonus number(5), salary_date date , work_hours number (3), constraint check_hours check (work_hours > 40 ) constraint sallary2_emp_fk foreign key (E_ID) references salloonee_employee1
);
Now, this is my code. The idea of the first constraint “check_hours ” is to add a bonus to the employee if his work hours exceeded 40 hours but I don’t know how to write it
Note: the first constraint “check_hours ” is not complete
Advertisement
Answer
Hmmm . . . I think you want a bonus
when the hours exceeds 40. If so:
constraint check_hours check (not (bonus = 0 and work_hours > 40))
Or equivalently:
constraint check_hours check (bonus > 0 or work_hours <= 40)
Or, if bonus
can be NULL
:
constraint check_hours check (not (coalesce(bonus, 0) = 0 and work_hours > 40))