I’m still learning how to use SQL, and I need some help creating this database.
I’ve created the following tables:
create table Worker
(Num_Worker number(20) PRIMARY KEY,
Name varchar2(30),
ID number(8),
Password varchar2(20));
create table Area
(Code_Area number(10) PRIMARY KEY,
Name varchar2(30),
Current_workers number(2)
Max_workers number(2));
create table Timetable
(ID_Timetable number(10) PRIMARY KEY,
Time_Entrance date,
Time_Exit date,
Code_Area number(10),
Num_Worker number(20),
Foreign Key (Num_Worker) references Worker(Num_Worker),
Foreign Key (Code_Area) references Area(Code_Area));
Supposedly, each worker can choose a area to work at, but each area has a limit or workers at the same time.
What would happen is a worker would create a new timetable, but before that timetable is created it should check the area that he chose to check if the “Current_workers” is the same value as “Max_workers”, and if it is it shouldn’t let it happen.
I’ve been trying to create a trigger for that, but I’ve had no luck in finding the correct syntax for it, and I’m not sure how to do it either, or if there’s a better way to do it than with a trigger.
This is all I’ve done so far:
create trigger limit_worker_per_zone
before insert
on Timetable
for each row
as
BEGIN
if (select Current_Workers from Area) >= (select Max_workers from Area) <-Not sure...
BEGIN
???
END
END
I’d really appreciate if you can help me in this. I’ll still be looking for more info myself meanwhile, but the more help the better.
1 Answer