-
Notifications
You must be signed in to change notification settings - Fork 2
/
Database.sql
1549 lines (1352 loc) · 67 KB
/
Database.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-- DDL:-
-- 1
CREATE TABLE address (
area_name VARCHAR2(30),
city_name VARCHAR2(30),
block_name VARCHAR2(30),
street_name VARCHAR2(30),
CONSTRAINT adrs_pk PRIMARY KEY (area_name,street_name,block_name,city_name));
-- 2
CREATE TABLE nationality(
nationality VARCHAR2(20) PRIMARY KEY);
-- 3
CREATE TABLE employee (
employee_id NUMBER(9) PRIMARY KEY,
full_name_ar VARCHAR2(100) NOT NULL,
full_name_en VARCHAR2(100) NOT NULL,
nationality VARCHAR2(20) NOT NULL REFERENCES nationality (nationality),
national_id NUMBER(9) NOT NULL UNIQUE,
sex CHAR NOT NULL ,
social_status CHAR NOT NULL,
salary NUMBER (8,2) CHECK ( salary >=0),
birh_place VARCHAR2(10) NOT NULL ,
date_of_birth DATE NOT NULL,
religion VARCHAR2(20) NOT NULL,
health_status VARCHAR2(40) NOT NULL,
number_of_family_members NUMBER(2) NOT NULL,
phone NUMBER(12) NOT NULL,
telephone_home NUMBER(9),
email VARCHAR2(30) NOT NULL,
area_name VARCHAR2(30) NOT NULL,
city_name VARCHAR2(30) NOT NULL,
block_name VARCHAR2(30) NOT NULL,
street_name VARCHAR2(30) NOT NULL,
employment_date DATE DEFAULT sysdate NOT NULL,
CONSTRAINT emp_sex_chk CHECK (sex IN ('M' , 'F')),
CONSTRAINT emp_social_status_chk CHECK ( social_status IN ('S','M','D' ) ),
CONSTRAINT EMP_FK_ADRES FOREIGN KEY (area_name,city_name,block_name,street_name) REFERENCES Address(area_name,city_name,block_name,street_name));
-- 4
CREATE TABLE building (
building_code CHAR (1) PRIMARY KEY,
building_desc VARCHAR2(100) );
-- 5
CREATE TABLE floor (
floor_number NUMBER(2),
building_code CHAR(1) NOT NULL REFERENCES building(building_code),
floor_desc VARCHAR2(100),
PRIMARY KEY (building_code, floor_number));
-- 6
CREATE TABLE room (
room_number NUMBER (2),
floor_number NUMBER (2),
building_code CHAR (1) NOT NULL,
capacity NUMBER (5) NOT NULL,
FOREIGN KEY (building_code,floor_number) REFERENCES floor(building_code,floor_number),
PRIMARY KEY (building_code ,floor_number,room_number));
-- 7
CREATE TABLE department (
department_id NUMBER (3) PRIMARY KEY,
department_name VARCHAR2(30) NOT NULL UNIQUE,
room_number NUMBER (2),
floor_number NUMBER (2),
building_code CHAR (1),
FOREIGN KEY (building_code,floor_number,room_number) REFERENCES room (building_code,floor_number,room_number) );
-- 8
CREATE TABLE majors_department (
majors_department_id NUMBER (3) PRIMARY KEY ,
majors_department_name VARCHAR2(30) NOT NULL UNIQUE,
room_number NUMBER (2),
floor_number NUMBER (2),
building_code CHAR (1),
FOREIGN KEY (building_code,floor_number,room_number) REFERENCES room (building_code,floor_number,room_number) );
-- 9
CREATE TABLE major (
major_id NUMBER (3) PRIMARY KEY,
major_name VARCHAR2(30) NOT NULL UNIQUE,
majors_department_id NUMBER (3) NOT NULL REFERENCES majors_department (majors_department_id) );
-- 10
CREATE TABLE course (
course_id VARCHAR2(10) PRIMARY KEY ,
course_name VARCHAR2(30) NOT NULL,
credit NUMBER (1) NOT NULL,
clevel NUMBER(1) NOT NULL,
description LONG,
majors_department_id NUMBER (3) NOT NULL REFERENCES Majors_Department (majors_department_id) );
-- 11
CREATE TABLE pre_required_courses (
course_id VARCHAR2(10) NOT NULL REFERENCES course(course_id) ,
pre_required_course_id VARCHAR2(10) NOT NULL REFERENCES course(course_id),
PRIMARY KEY (course_id,pre_required_course_id));
-- 12
CREATE TABLE teacher (
teacher_id NUMBER (9) NOT NULL REFERENCES employee(employee_id) ,
teacher_start_date DATE DEFAULT sysdate,
teacher_end_date DATE,
majors_department_id NUMBER (3) NOT NULL REFERENCES majors_department (majors_department_id),
salary NUMBER (8,2) CHECK (salary >=0) ,
teacher_start_year NUMBER(4) DEFAULT EXTRACT (YEAR FROM sysdate) NOT NULL,
teacher_start_semester NUMBER(1) NOT NULL,
CONSTRAINT tchr_pk PRIMARY KEY (teacher_id , teacher_start_year , teacher_start_semester ),
CONSTRAINT tchr_strt_smstr_chk CHECK (teacher_start_semester IN (1,2,3)) );
-- 13
CREATE TABLE manager (
manager_id NUMBER (9) NOT NULL REFERENCES employee(employee_id),
manager_start_date DATE DEFAULT sysdate,
manager_end_date DATE,
salary NUMBER (8,2) check (salary >=0),
manager_grade VARCHAR2(15) NOT NULL,
majors_department_id NUMBER (3) REFERENCES majors_department (majors_department_id) ,
department_id NUMBER (3) REFERENCES department (department_id) ,
manager_start_year NUMBER(4) DEFAULT EXTRACT (YEAR FROM sysdate) NOT NULL,
manager_start_semester NUMBER(1) NOT NULL,
CONSTRAINT mngr_pk PRIMARY KEY (manager_id , manager_start_year , manager_start_semester ),
CONSTRAINT mngr_strt_smstr_chk CHECK (manager_start_semester IN (1,2,3)),
CONSTRAINT mngr_dept_chk CHECK ( (majors_department_id IS NULL AND department_id IS NOT NULL) OR (department_id IS NULL AND majors_department_id IS NOT NULL) ) );
-- 14
CREATE TABLE security (
security_id NUMBER (9) NOT NULL REFERENCES employee(employee_id) ,
security_start_date DATE DEFAULT sysdate,
security_end_date DATE,
salary NUMBER (8,2) CHECK (salary >=0),
department_id NUMBER (3) NOT NULL REFERENCES department (department_id),
security_start_year NUMBER(4) DEFAULT EXTRACT (YEAR FROM sysdate) NOT NULL,
security_start_semester NUMBER(1) NOT NULL,
CONSTRAINT security_pk PRIMARY KEY (security_id , security_start_year , security_start_semester ),
CONSTRAINT security_strt_smstr_chk CHECK (security_start_semester IN (1,2,3)));
-- 15
CREATE TABLE secretary (
secretary_id NUMBER (9) NOT NULL REFERENCES employee(employee_id) ,
secretary_start_date DATE DEFAULT sysdate,
secretary_end_date DATE,
salary NUMBER (8,2) CHECK (salary >=0),
majors_department_id NUMBER (3) REFERENCES majors_department (majors_department_id) ,
department_id NUMBER (3) REFERENCES department (department_id) ,
secretary_start_year NUMBER(4) DEFAULT EXTRACT (YEAR FROM sysdate) NOT NULL,
secretary_start_semester NUMBER(1) NOT NULL,
CONSTRAINT secretary_pk PRIMARY KEY (secretary_id , secretary_start_year , secretary_start_semester ),
CONSTRAINT secretary_strt_smstr_chk CHECK (secretary_start_semester IN (1,2,3)),
CONSTRAINT secretary_dept_chk CHECK ( (majors_department_id IS NULL AND department_id IS NOT NULL) OR (department_id IS NULL AND majors_department_id IS NOT NULL) ) );
-- 16
CREATE TABLE item (
item_id NUMBER (3) PRIMARY KEY,
item_name VARCHAR2(30) NOT NULL,
item_description VARCHAR2(200) NOT NULL);
-- 17
CREATE TABLE room_items (
item_id NUMBER (3) NOT NULL REFERENCES item (item_id) ,
room_number NUMBER (2) NOT NULL ,
floor_number NUMBER (2),
building_code CHAR (1),
FOREIGN KEY (room_number , floor_number , building_code) REFERENCES room (room_number , floor_number , building_code) ,
quantity NUMBER (5) NOT NULL,
PRIMARY KEY (item_id , room_number , floor_number , building_code));
-- 18
CREATE TABLE study_plan (
plan_number NUMBER (3),
major_id NUMBER (3) NOT NULL REFERENCES major (major_id) ,
PRIMARY KEY (plan_number, major_id));
-- 19
CREATE TABLE study_plan_courses (
plan_number NUMBER (3) NOT NULL ,
major_id NUMBER (3),
course_id VARCHAR2(10) NOT NULL REFERENCES course (course_id),
year NUMBER(4) NOT NULL,
semester NUMBER (1) ,
FOREIGN KEY (plan_number, major_id) REFERENCES study_plan (plan_number, major_id),
PRIMARY KEY (plan_number, major_id, course_id),
CONSTRAINT stdy_pln_smstr_chk CHECK (semester IN (1,2,3)));
-- 20
CREATE TABLE student (
student_id NUMBER(9) PRIMARY KEY,
full_name_ar VARCHAR2(100) NOT NULL,
full_name_en VARCHAR2(100) NOT NULL,
nationality VARCHAR2(20) NOT NULL REFERENCES nationality (nationality) ,
national_id NUMBER(9) NOT NULL,
sex CHAR NOT NULL ,
social_status CHAR NOT NULL ,
guardian_name VARCHAR2(30) NOT NULL,
guardian_national_id NUMBER(9) NOT NULL,
guardian_relation VARCHAR2(10) NOT NULL,
birh_place VARCHAR2(10) NOT NULL ,
date_of_birth DATE NOT NULL,
religion VARCHAR2(20) NOT NULL,
health_status VARCHAR2(40) NOT NULL ,
mother_name VARCHAR2(30) NOT NULL,
mother_job VARCHAR2(20) NOT NULL ,
mother_job_desc VARCHAR2(100) NOT NULL,
father_job VARCHAR2(20) NOT NULL ,
father_job_desc VARCHAR2(100) NOT NULL,
parents_status VARCHAR2(30) NOT NULL ,
number_of_family_members NUMBER(2) NOT NULL,
family_university_students NUMBER(2) NOT NULL,
social_affairs VARCHAR2(40) NOT NULL ,
phone NUMBER(12) ,
telephone_home NUMBER(9) ,
emergency_phone NUMBER(12) NOT NULL,
email VARCHAR2(30) ,
tawjihi_GPA NUMBER(4,2) NOT NULL,
tawjihi_field CHAR NOT NULL,
area_name VARCHAR2(30) NOT NULL,
city_name VARCHAR2(30) NOT NULL,
block_name VARCHAR2(30) NOT NULL,
street_name VARCHAR2(30) NOT NULL,
major_id NUMBER(3) NOT NULL REFERENCES major(major_id) ,
balance NUMBER(5) NOT NULL,
FOREIGN KEY (area_name,city_name,block_name,street_name) REFERENCES address(area_name,city_name,block_name,street_name),
CONSTRAINT stdnt_sex_chk CHECK (sex IN ('M' , 'F')),
CONSTRAINT stdnt_social_status_chk CHECK ( social_status IN ('S','M','D' ) ),
CONSTRAINT stdnt_twj_fld_chk CHECK (tawjihi_field IN ('S' , 'L' )));
-- 21
CREATE TABLE academic_advice (
teacher_id NUMBER (9) NOT NULL ,
year NUMBER(4) DEFAULT EXTRACT (YEAR FROM sysdate),
semester NUMBER (1),
student_id NUMBER(9) NOT NULL REFERENCES student (student_id) ,
CONSTRAINT acdmic_advc_fk_tchr FOREIGN KEY (teacher_id ,year ,semester) REFERENCES teacher(teacher_id ,teacher_start_year , teacher_start_semester),
PRIMARY KEY (teacher_id, year, semester, student_id) );
-- 22
CREATE TABLE section (
section_number NUMBER (3),
course_id VARCHAR2(10) NOT NULL REFERENCES course (course_id) ,
teacher_id NUMBER (9) ,
year NUMBER(4) DEFAULT EXTRACT (YEAR FROM sysdate),
semester NUMBER (1) ,
CONSTRAINT section_fk_tchr FOREIGN KEY (teacher_id ,year ,semester) REFERENCES teacher(teacher_id ,teacher_start_year , teacher_start_semester),
PRIMARY KEY (section_number, course_id, year, semester),
CONSTRAINT section_smstr_chk CHECK (semester IN (1,2,3)));
-- 23
CREATE TABLE enroll (
student_id NUMBER(9) NOT NULL REFERENCES student (student_id) ,
course_id VARCHAR2(10) ,
section_number NUMBER(3) NOT NULL ,
year NUMBER(4) DEFAULT EXTRACT (YEAR FROM sysdate),
semester NUMBER(1) ,
grade_mid NUMBER (2) DEFAULT NULL ,
grade_final NUMBER (3) DEFAULT NULL,
FOREIGN KEY (section_number , course_id , year , semester) REFERENCES section (section_number , course_id , year , semester) ,
PRIMARY KEY (student_id , course_id , section_number , year , semester),
CONSTRAINT eroll_grade_chk CHECK ((grade_final+grade_mid >=40)and (grade_final+grade_mid <=100 )));
-- 24
CREATE TABLE section_rooms (
section_number NUMBER (3) NOT NULL ,
course_id VARCHAR2 (10) ,
year NUMBER(4) DEFAULT EXTRACT (YEAR FROM sysdate),
semester NUMBER (1) ,
room_number NUMBER (2),
floor_number NUMBER (2),
building_code CHAR (1) NOT NULL ,
day DATE NOT NULL,
start_time DATE ,
end_time DATE ,
FOREIGN KEY (building_code,floor_number,room_number) REFERENCES room (building_code,floor_number,room_number) ,
FOREIGN KEY (section_number , course_id , year , semester ) REFERENCES section (section_number , course_id , year , semester ) ,
PRIMARY KEY (building_code,floor_number, year , semester, room_number, start_time,day));
----------------------------------------------------------------------------------------------------------
CREATE TABLE Address_log (
street_name VARCHAR2(30) NOT NULL,
block_name VARCHAR2(30) NOT NULL,
city_name VARCHAR2(30) NOT NULL,
area_name VARCHAR2(30) NOT NULL,
action_name char (6) NOT NULL,
action_date date DEFAULT sysdate NOT NULL,
action_user VARCHAR2(30) DEFAULT user NOT NULL);
CREATE OR REPLACE TRIGGER ai_address_trgr AFTER INSERT ON address
for each row
begin
INSERT INTO address_log VALUES (:new.street_name ,:new.block_name ,:new.city_name ,:new.area_name ,'INSERT' ,DEFAULT,DEFAULT );
end;
/
CREATE OR REPLACE TRIGGER au_address_trgr AFTER UPDATE ON address
for each row
begin
INSERT INTO ADDRESS_LOG VALUES (:old.street_name ,:old.block_name ,:old.city_name ,:old.area_name , 'DELETE',DEFAULT,DEFAULT );
INSERT INTO ADDRESS_LOG VALUES (:new.street_name ,:new.block_name ,:new.city_name ,:new.area_name , 'INSERT',DEFAULT,DEFAULT );
end;
/
CREATE OR REPLACE TRIGGER ad_address_trgr AFTER DELETE ON address
for each row
begin
INSERT INTO ADDRESS_LOG VALUES (:old.street_name ,:old.block_name ,:old.city_name ,:old.area_name ,'DELETE' ,DEFAULT ,DEFAULT );
end;
/
CREATE TABLE employee_log (
employee_id NUMBER(9) ,
Full_name_ar VARCHAR2(100) NOT NULL,
Full_name_en VARCHAR2(100) NOT NULL,
Nationality VARCHAR2(20) NOT NULL,
national_id NUMBER(9) NOT NULL,
sex CHAR NOT NULL ,
social_status CHAR NOT NULL,
salary NUMBER (8,2) CHECK ( salary >=0),
birh_place VARCHAR2(10) NOT NULL ,
date_of_birth DATE NOT NULL,
religion VARCHAR2(20) NOT NULL,
health_status VARCHAR2(40) NOT NULL,
number_of_family_members NUMBER(2) NOT NULL,
phone NUMBER(12) NOT NULL,
telephone_home NUMBER(9),
email VARCHAR2(30) NOT NULL,
area_name VARCHAR2(30) NOT NULL,
city_name VARCHAR2(30) NOT NULL,
block_name VARCHAR2(30) NOT NULL,
street_name VARCHAR2(30) NOT NULL,
employment_date DATE NOT NULL,
action_name char(6) NOT NULL ,
action_date date DEFAULT sysdate NOT NULL,
action_user VARCHAR2(30) DEFAULT user NOT NULL);
CREATE OR REPLACE TRIGGER ai_employee_trgr AFTER INSERT ON employee
for each row
begin
INSERT INTO employee_log VALUES (:new.employee_id ,:new.Full_name_ar ,:new.Full_name_en ,:new.nationality ,:new.national_id
,:new.sex ,:new.social_status ,:new.salary ,:new.birh_place , :new.date_of_birth ,:new.religion ,:new.health_status ,:new.number_of_family_members
,:new.phone ,:new.telephone_home ,:new.email ,:new.area_name ,:new.city_name ,:new.block_name ,:new.street_name ,:new.employment_date ,'INSERT' ,DEFAULT ,DEFAULT );
end;
/
CREATE OR REPLACE TRIGGER au_employee_trgr AFTER UPDATE ON employee
for each row
begin
INSERT INTO employee_log VALUES (:old.employee_id ,:old.Full_name_ar ,:old.Full_name_en ,:old.nationality ,:old.national_id,:new.sex ,:old.social_status ,:old.salary ,:old.birh_place,:old.date_of_birth ,:old.religion ,:old.health_status ,:old.number_of_family_members ,:old.phone ,:old.telephone_home ,:old.email , :old.area_name ,:old.city_name ,:old.block_name ,:old.street_name ,:old.employment_date ,'DELETE' ,DEFAULT ,DEFAULT );
INSERT INTO employee_log VALUES (:new.employee_id ,:new.Full_name_ar ,:new.Full_name_en ,:new.nationality ,:new.national_id,:new.sex ,:new.social_status ,:new.salary ,:new.birh_place,:new.date_of_birth ,:new.religion ,:new.health_status ,:new.number_of_family_members ,:new.phone ,:new.telephone_home ,:new.email , :new.area_name ,:new.city_name ,:new.block_name ,:new.street_name ,:new.employment_date ,'INSERT' ,DEFAULT ,DEFAULT );
end;
/
CREATE OR REPLACE TRIGGER ad_employee_trgr AFTER DELETE ON employee
for each row
begin
INSERT INTO employee_log VALUES (:old.employee_id ,:old.Full_name_ar ,:old.Full_name_en ,:old.nationality ,:old.national_id,:old.sex ,:old.social_status ,:old.salary ,:old.birh_place, :old.date_of_birth ,:old.religion ,:old.health_status ,:old.number_of_family_members,:old.phone ,:old.telephone_home ,:old.email ,:old.area_name ,:old.city_name ,:old.block_name ,:old.street_name , :old.employment_date ,'DELETE' ,DEFAULT ,DEFAULT );
end;
/
CREATE TABLE building_log (
building_code CHAR (1) ,
building_desc VARCHAR2 (100),
action_name char(6) NOT NULL ,
action_date date DEFAULT sysdate NOT NULL,
action_user VARCHAR2(30) DEFAULT user NOT NULL );
CREATE OR REPLACE TRIGGER ai_building_trgr AFTER INSERT ON building
for each row
begin
INSERT INTO building_log VALUES (:new.building_code,:new.building_desc ,'INSERT' ,DEFAULT,DEFAULT );
end;
/
CREATE OR REPLACE TRIGGER au_building_trgr AFTER UPDATE ON building
for each row
begin
INSERT INTO building_log VALUES (:old.building_code,:old.building_desc,'DELETE' ,DEFAULT,DEFAULT );
INSERT INTO building_log VALUES (:new.building_code,:new.building_desc,'INSERT' ,DEFAULT,DEFAULT );
end;
/
CREATE OR REPLACE TRIGGER ad_building_trgr AFTER DELETE ON building
FOR each row
begin
INSERT INTO building_log VALUES (:old.building_code,:old.building_desc,'DELETE' ,DEFAULT,DEFAULT );
end;
/
CREATE TABLE floor_log (
floor_number NUMBER (2),
building_code CHAR (1),
floor_desc VARCHAR2 (100),
action_name char(6) NOT NULL ,
action_date date DEFAULT sysdate NOT NULL,
action_user VARCHAR2(30) DEFAULT user NOT NULL );
CREATE OR REPLACE TRIGGER ai_floor_trgr AFTER INSERT ON floor
for each row
begin
INSERT INTO floor_log VALUES (:new.floor_number ,:new.building_code,:new.floor_desc ,'INSERT' ,DEFAULT,DEFAULT );
end;
/
CREATE OR REPLACE TRIGGER au_floor_trgr AFTER UPDATE ON floor
for each row
begin
INSERT INTO floor_log VALUES (:old.floor_number ,:old.building_code,:old.floor_desc ,'DELETE' ,DEFAULT,DEFAULT );
INSERT INTO floor_log VALUES (:new.floor_number ,:new.building_code,:new.floor_desc ,'INSERT' ,DEFAULT,DEFAULT );
end;
/
CREATE OR REPLACE TRIGGER ad_floor_trgr AFTER DELETE ON floor
for each row
begin
INSERT INTO floor_log VALUES (:old.floor_number ,:old.building_code,:old.floor_desc,'DELETE' , DEFAULT ,DEFAULT );
end;
/
CREATE TABLE room_log (
room_number NUMBER (2),
floor_number NUMBER (2),
building_code CHAR (1),
capacity NUMBER (5) NOT NULL,
action_name char(6) NOT NULL ,
action_date date DEFAULT sysdate NOT NULL,
action_user VARCHAR2(30) DEFAULT user NOT NULL);
CREATE OR REPLACE TRIGGER ai_room_trgr AFTER INSERT ON room
for each row
begin
INSERT INTO room_log VALUES (:new.room_number ,:new.floor_number ,:new.building_code,:new.capacity ,'INSERT' ,DEFAULT,DEFAULT );
end;
/
CREATE OR REPLACE TRIGGER au_room_trgr AFTER UPDATE ON room
for each row
begin
INSERT INTO room_log VALUES (:old.room_number ,:old.floor_number ,:old.building_code,:old.capacity ,'DELETE' ,DEFAULT,DEFAULT );
INSERT INTO room_log VALUES (:new.room_number ,:new.floor_number ,:new.building_code,:new.capacity ,'INSERT' ,DEFAULT,DEFAULT );
end;
/
CREATE OR REPLACE TRIGGER ad_room_trgr AFTER DELETE ON room
for each row
begin
INSERT INTO room_log VALUES (:old.room_number ,:old.floor_number ,:old.building_code,:old.capacity ,'DELETE' ,DEFAULT,DEFAULT );
end;
/
CREATE TABLE Department_log (
Department_id NUMBER (3),
Department_name VARCHAR2(30) NOT NULL,
room_number NUMBER (2),
floor_number NUMBER (2),
building_code CHAR (1),
action_name char(6) NOT NULL ,
action_date date DEFAULT sysdate NOT NULL,
action_user VARCHAR2(30) DEFAULT user NOT NULL);
CREATE OR REPLACE TRIGGER ai_Department_trgr AFTER INSERT ON Department
for each row
begin
INSERT INTO Department_log VALUES (:new.Department_id ,:new.Department_name ,:new.room_number,:new.floor_number ,:new.building_code ,'INSERT',DEFAULT,DEFAULT);
end;
/
CREATE OR REPLACE TRIGGER au_Department_trgr AFTER UPDATE ON Department
for each row
begin
INSERT INTO Department_log VALUES (:old.Department_id ,:old.Department_name ,:old.room_number,:old.floor_number ,:old.building_code ,'DELETE',DEFAULT,DEFAULT);
INSERT INTO Department_log VALUES (:new.Department_id ,:new.Department_name ,:new.room_number,:new.floor_number ,:new.building_code ,'INSERT',DEFAULT,DEFAULT);
end;
/
CREATE OR REPLACE TRIGGER ad_Department_trgr AFTER DELETE ON Department
for each row
begin
INSERT INTO Department_log VALUES (:old.Department_id ,:old.Department_name ,:old.room_number,:old.floor_number ,:old.building_code ,'DELETE',DEFAULT,DEFAULT);
end;
/
CREATE TABLE Majors_Department_log (
Majors_Department_id NUMBER (3),
Majors_Department_name VARCHAR2(30) NOT NULL ,
room_number NUMBER (2),
floor_number NUMBER (2),
building_code CHAR (1),
action_name char(6) NOT NULL ,
action_date date DEFAULT sysdate NOT NULL,
action_user VARCHAR2(30) DEFAULT user NOT NULL);
CREATE OR REPLACE TRIGGER ai_Majors_Department_trgr AFTER INSERT ON Majors_Department
for each row
begin
INSERT INTO Majors_Department_log VALUES (:new.Majors_Department_id ,:new.Majors_Department_name ,:new.room_number,:new.floor_number ,:new.building_code ,'INSERT',DEFAULT,DEFAULT);
end;
/
CREATE OR REPLACE TRIGGER au_Majors_Department_trgr AFTER UPDATE ON Majors_Department
for each row
begin
INSERT INTO Majors_Department_log VALUES (:old.Majors_Department_id ,:old.Majors_Department_name ,:old.room_number,:old.floor_number ,:old.building_code ,'DELETE',DEFAULT,DEFAULT);
INSERT INTO Majors_Department_log VALUES (:new.Majors_Department_id ,:new.Majors_Department_name ,:new.room_number,:new.floor_number ,:new.building_code ,'INSERT',DEFAULT,DEFAULT);
end;
/
CREATE OR REPLACE TRIGGER ad_Majors_Department_trgr AFTER DELETE ON Majors_Department
for each row
begin
INSERT INTO Majors_Department_log VALUES (:old.Majors_Department_id ,:old.Majors_Department_name ,:old.room_number,:old.floor_number ,:old.building_code ,'DELETE',DEFAULT,DEFAULT);
end;
/
CREATE TABLE major_log (
major_id NUMBER (3) ,
major_name VARCHAR2(30) NOT NULL ,
Majors_Department_id NUMBER (3) ,
action_name char(6) NOT NULL ,
action_date date DEFAULT sysdate NOT NULL,
action_user VARCHAR2(30) DEFAULT user NOT NULL);
CREATE OR REPLACE TRIGGER ai_major_trgr AFTER INSERT ON major
for each row
begin
INSERT INTO major_log VALUES (:new.major_id ,:new.major_name ,:new.Majors_Department_id ,'INSERT',DEFAULT,DEFAULT);
end;
/
CREATE OR REPLACE TRIGGER au_major_trgr AFTER UPDATE ON major
for each row
begin
INSERT INTO major_log VALUES (:old.major_id ,:old.major_name ,:old.Majors_Department_id ,'DELETE',DEFAULT,DEFAULT);
INSERT INTO major_log VALUES (:new.major_id ,:new.major_name ,:new.Majors_Department_id ,'INSERT',DEFAULT,DEFAULT);
end;
/
CREATE OR REPLACE TRIGGER ad_major_trgr AFTER DELETE ON major
for each row
begin
INSERT INTO major_log VALUES (:old.major_id ,:old.major_name ,:old.Majors_Department_id ,'DELETE',DEFAULT,DEFAULT);
end;
/
CREATE TABLE course_log (
course_id VARCHAR2(10),
course_name VARCHAR2(30) NOT NULL,
credit NUMBER (1) NOT NULL,
clevel NUMBER (1) NOT NULL,
Majors_Department_id NUMBER (3),
action_name char(6) NOT NULL ,
action_date date DEFAULT sysdate NOT NULL,
action_user VARCHAR2(30) DEFAULT user NOT NULL);
CREATE OR REPLACE TRIGGER ai_course_trgr AFTER INSERT ON course
for each row
begin
INSERT INTO course_log VALUES (:new.course_id ,:new.course_name ,:new.credit , :new.clevel ,:new.Majors_Department_id ,'INSERT',DEFAULT,DEFAULT);
end;
/
CREATE OR REPLACE TRIGGER au_course_trgr AFTER UPDATE ON course
for each row
begin
INSERT INTO course_log VALUES (:old.course_id ,:old.course_name ,:old.credit , :old.clevel ,:old.Majors_Department_id,'DELETE',DEFAULT,DEFAULT);
INSERT INTO course_log VALUES (:new.course_id ,:new.course_name ,:new.credit , :new.clevel ,:new.Majors_Department_id,'INSERT',DEFAULT,DEFAULT);
end;
/
CREATE OR REPLACE TRIGGER ad_course_trgr AFTER DELETE ON course
for each row
begin
INSERT INTO course_log VALUES (:old.course_id ,:old.course_name ,:old.credit , :old.clevel ,:old.Majors_Department_id,'DELETE',DEFAULT,DEFAULT);
end;
/
CREATE TABLE teacher_log (
teacher_id NUMBER (9),
teacher_start_date DATE,
teacher_end_date DATE,
majors_department_id NUMBER (3),
salary NUMBER (8,2) check (salary >=0),
teacher_start_year NUMBER(4) NOT NULL,
teacher_start_semester NUMBER(1) NOT NULL,
action_name char(6) NOT NULL ,
action_date date DEFAULT sysdate NOT NULL,
action_user VARCHAR2(30) DEFAULT user NOT NULL);
CREATE OR REPLACE TRIGGER ai_teacher_trgr AFTER INSERT ON teacher
for each row
begin
INSERT INTO teacher_log VALUES (:new.teacher_id ,:new.teacher_start_date ,:new.teacher_end_date,:new.majors_department_id,:new.salary , :new.teacher_start_year , :new.teacher_start_semester , 'INSERT' ,DEFAULT,DEFAULT );
end;
/
CREATE OR REPLACE TRIGGER au_teacher_trgr AFTER UPDATE ON teacher
for each row
begin
INSERT INTO teacher_log VALUES (:old.Teacher_id ,:old.teacher_Start_Date ,:old.teacher_End_Date,:old.Majors_Department_id,:old.salary , :old.teacher_start_year , :old.teacher_start_semester , 'DELETE' ,DEFAULT,DEFAULT );
INSERT INTO teacher_log VALUES (:new.Teacher_id ,:new.teacher_Start_Date ,:new.teacher_End_Date,:new.Majors_Department_id,:new.salary , :new.teacher_start_year , :new.teacher_start_semester , 'INSERT' ,DEFAULT,DEFAULT );
end;
/
CREATE OR REPLACE TRIGGER ad_teacher_trgr AFTER DELETE ON teacher
for each row
begin
INSERT INTO teacher_log VALUES (:old.Teacher_id ,:old.teacher_Start_Date ,:old.teacher_End_Date,:old.Majors_Department_id,:old.salary , :old.teacher_start_year , :old.teacher_start_semester , 'DELETE' ,DEFAULT,DEFAULT );
end;
/
CREATE TABLE manager_log (
manager_id NUMBER (9) ,
manager_Start_Date DATE DEFAULT sysdate,
manager_End_Date DATE,
salary NUMBER (8,2) check (salary >=0),
manager_grade VARCHAR2(15) NOT NULL,
majors_department_id NUMBER (3) ,
department_id NUMBER (3) ,
manager_start_year NUMBER(4) NOT NULL,
manager_start_semester NUMBER(1) NOT NULL,
action_name char(6) NOT NULL ,
action_date date DEFAULT sysdate NOT NULL,
action_user VARCHAR2(30) DEFAULT user NOT NULL);
CREATE OR REPLACE TRIGGER ai_manager_trgr AFTER INSERT ON manager
for each row
begin
INSERT INTO manager_log VALUES (:new.manager_id ,:new.manager_Start_Date ,:new.manager_End_Date ,:new.salary ,:new.Manager_Grade ,:new.Majors_Department_id ,:new.Department_id , :new.manager_start_year , :new.manager_start_semester , 'INSERT' ,DEFAULT,DEFAULT );
end;
/
CREATE OR REPLACE TRIGGER au_manager_trgr AFTER UPDATE ON manager
for each row
begin
INSERT INTO manager_log VALUES (:old.manager_id ,:old.manager_Start_Date ,:old.manager_End_Date ,:old.salary ,:old.Manager_Grade ,:old.Majors_Department_id ,:old.Department_id , :old.manager_start_year , :old.manager_start_semester , 'DELETE' ,DEFAULT,DEFAULT );
INSERT INTO manager_log VALUES (:new.manager_id ,:new.manager_Start_Date ,:new.manager_End_Date ,:new.salary ,:new.Manager_Grade ,:new.Majors_Department_id ,:new.Department_id , :new.manager_start_year , :new.manager_start_semester , 'INSERT' ,DEFAULT,DEFAULT );
end;
/
CREATE OR REPLACE TRIGGER ad_manager_trgr AFTER DELETE ON manager
for each row
begin
INSERT INTO manager_log VALUES (:old.manager_id ,:old.manager_Start_Date ,:old.manager_End_Date ,:old.salary ,:old.Manager_Grade ,:old.Majors_Department_id ,:old.Department_id , :old.manager_start_year , :old.manager_start_semester , 'DELETE' ,DEFAULT,DEFAULT );
end;
/
CREATE TABLE security_log (
Security_id NUMBER (9) ,
security_Start_Date DATE DEFAULT sysdate,
security_End_Date DATE,
salary NUMBER (8,2) ,
Department_id NUMBER (3),
security_start_year NUMBER(4) NOT NULL,
security_start_semester NUMBER(1) NOT NULL,
action_name char(6) NOT NULL ,
action_date date DEFAULT sysdate NOT NULL,
action_user VARCHAR2(30) DEFAULT user NOT NULL);
CREATE OR REPLACE TRIGGER ai_Security_trgr AFTER INSERT ON Security
for each row
begin
INSERT INTO Security_log VALUES (:new.Security_id ,:new.security_Start_Date ,:new.security_End_Date ,:new.salary ,:new.Department_id, :new.security_start_year , :new.security_start_semester , 'INSERT' ,DEFAULT,DEFAULT );
end;
/
CREATE OR REPLACE TRIGGER au_Security_trgr AFTER UPDATE ON Security
for each row
begin
INSERT INTO Security_log VALUES (:old.Security_id ,:old.security_Start_Date ,:old.security_End_Date ,:old.salary ,:old.Department_id, :old.security_start_year , :old.security_start_semester , 'DELETE' ,DEFAULT,DEFAULT );
INSERT INTO Security_log VALUES (:new.Security_id ,:new.security_Start_Date ,:new.security_End_Date ,:new.salary ,:new.Department_id, :new.security_start_year , :new.security_start_semester , 'INSERT' ,DEFAULT,DEFAULT );
end;
/
CREATE OR REPLACE TRIGGER ad_Security_trgr AFTER DELETE ON Security
for each row
begin
INSERT INTO Security_log VALUES (:old.Security_id ,:old.security_Start_Date ,:old.security_End_Date ,:old.salary ,:old.Department_id, :old.security_start_year , :old.security_start_semester , 'DELETE' ,DEFAULT,DEFAULT );
end;
/
CREATE TABLE secretary_log (
secretary_id NUMBER (9) ,
secretary_start_date DATE DEFAULT sysdate,
secretary_end_date DATE,
salary NUMBER (8,2) CHECK (salary >=0),
majors_department_id NUMBER (3) ,
department_id NUMBER (3),
secretary_start_year NUMBER(4) NOT NULL,
secretary_start_semester NUMBER(1) NOT NULL,
action_name char (6) NOT NULL,
action_date date DEFAULT sysdate NOT NULL,
action_user VARCHAR2(30) DEFAULT user NOT NULL);
CREATE OR REPLACE TRIGGER ai_secretary_trgr AFTER INSERT ON secretary
for each row
begin
INSERT INTO Secretary_log VALUES (:new.Secretary_id ,:new.secretary_Start_Date ,:new.secretary_End_Date , :new.salary , :new.majors_department_id ,:new.Department_id , :new.secretary_start_year , :new.secretary_start_semester , 'INSERT' ,DEFAULT,DEFAULT );
end;
/
CREATE OR REPLACE TRIGGER au_Secretary_trgr AFTER UPDATE ON Secretary
for each row
begin
INSERT INTO Secretary_log VALUES (:old.Secretary_id ,:old.secretary_Start_Date ,:old.secretary_End_Date , :old.salary ,:old.Majors_Department_id ,:old.Department_id , :old.secretary_start_year , :old.secretary_start_semester , 'DELETE' ,DEFAULT,DEFAULT );
INSERT INTO Secretary_log VALUES (:new.Secretary_id ,:new.secretary_Start_Date ,:new.secretary_End_Date , :new.salary ,:new.Majors_Department_id ,:new.Department_id , :new.secretary_start_year , :new.secretary_start_semester , 'INSERT' ,DEFAULT,DEFAULT );
end;
/
CREATE OR REPLACE TRIGGER ad_Secretary_trgr AFTER DELETE ON Secretary
for each row
begin
INSERT INTO Secretary_log VALUES (:old.Secretary_id ,:old.secretary_Start_Date ,:old.secretary_End_Date , :old.salary ,:old.Majors_Department_id ,:old.Department_id , :old.secretary_start_year , :old.secretary_start_semester , 'DELETE' ,DEFAULT,DEFAULT );
end;
/
CREATE TABLE item_log (
item_id NUMBER (3) ,
item_name VARCHAR2(30) ,
item_description VARCHAR2(200),
action_name char (6) NOT NULL,
action_date date DEFAULT sysdate NOT NULL,
action_user VARCHAR2(30) DEFAULT user NOT NULL);
CREATE OR REPLACE TRIGGER ai_item_trgr AFTER INSERT ON item
for each row
begin
INSERT INTO item_log VALUES (:new.item_id ,:new.item_name ,:new.item_description ,'INSERT' ,DEFAULT,DEFAULT );
end;
/
CREATE OR REPLACE TRIGGER au_item_trgr AFTER UPDATE ON item
for each row
begin
INSERT INTO item_log VALUES (:old.item_id ,:old.item_name ,:old.item_description ,'DELETE' ,DEFAULT,DEFAULT );
INSERT INTO item_log VALUES (:new.item_id ,:new.item_name ,:new.item_description ,'INSERT' ,DEFAULT,DEFAULT );
end;
/
CREATE OR REPLACE TRIGGER ad_item_trgr AFTER DELETE ON item
for each row
begin
INSERT INTO item_log VALUES (:old.item_id ,:old.item_name ,:old.item_description ,'DELETE' ,DEFAULT,DEFAULT );
end;
/
CREATE TABLE room_items_log (
item_id NUMBER (3) ,
room_number NUMBER (2),
floor_number NUMBER (2),
building_code CHAR (1),
quantity NUMBER (5),
action_name char (6) NOT NULL,
action_date date DEFAULT sysdate NOT NULL,
action_user VARCHAR2(30) DEFAULT user NOT NULL);
CREATE OR REPLACE TRIGGER ai_room_items_trgr AFTER INSERT ON room_items
for each row
begin
INSERT INTO room_items_log VALUES (:new.item_id ,:new.room_number ,:new.floor_number ,:new.building_code ,:new.quantity ,'INSERT' ,DEFAULT,DEFAULT );
end;
/
CREATE OR REPLACE TRIGGER au_room_items_trgr AFTER UPDATE ON room_items
for each row
begin
INSERT INTO room_items_log VALUES (:old.item_id ,:old.room_number ,:old.floor_number ,:old.building_code ,:old.quantity ,'INSERT' ,DEFAULT,DEFAULT );
INSERT INTO room_items_log VALUES (:new.item_id ,:new.room_number ,:new.floor_number ,:new.building_code ,:new.quantity ,'INSERT' ,DEFAULT,DEFAULT );
end;
/
CREATE OR REPLACE TRIGGER ad_room_items_trgr AFTER DELETE ON room_items
for each row
begin
INSERT INTO room_items_log VALUES (:old.item_id ,:old.room_number ,:old.floor_number ,:old.building_code ,:old.quantity ,'INSERT' ,DEFAULT,DEFAULT );
end;
/
CREATE TABLE study_plan_log (
plan_number NUMBER (3),
major_id NUMBER (3),
action_name char (6) NOT NULL,
action_date date DEFAULT sysdate NOT NULL,
action_user VARCHAR2(30) DEFAULT user NOT NULL);
CREATE OR REPLACE TRIGGER ai_study_plan_trgr AFTER INSERT ON study_plan
for each row
begin
INSERT INTO study_plan_log VALUES (:new.plan_number ,:new.major_id ,'INSERT' ,DEFAULT,DEFAULT );
end;
/
CREATE OR REPLACE TRIGGER au_study_plan_trgr AFTER UPDATE ON study_plan
for each row
begin
INSERT INTO study_plan_log VALUES (:old.plan_number ,:old.major_id ,'DELETE' ,DEFAULT,DEFAULT );
INSERT INTO study_plan_log VALUES (:new.plan_number ,:new.major_id ,'INSERT' ,DEFAULT,DEFAULT );
end;
/
CREATE OR REPLACE TRIGGER ad_study_plan_trgr AFTER DELETE ON study_plan
for each row
begin
INSERT INTO study_plan_log VALUES (:old.plan_number ,:old.major_id ,'DELETE' ,DEFAULT,DEFAULT );
end;
/
CREATE TABLE academic_advice_log (
teacher_id NUMBER (9),
student_id NUMBER(9),
year NUMBER(4) DEFAULT EXTRACT (YEAR FROM sysdate),
semester NUMBER (1) ,
action_name char(6) NOT NULL ,
action_date date DEFAULT sysdate NOT NULL,
action_user VARCHAR2(30) DEFAULT user NOT NULL);
CREATE OR REPLACE TRIGGER ai_academic_advice_trgr AFTER INSERT ON academic_advice
for each row
begin
INSERT INTO academic_advice_log VALUES (:new.teacher_id ,:new.student_id ,:new.year ,:new.semester,'INSERT' ,DEFAULT ,DEFAULT );
end;
/
CREATE OR REPLACE TRIGGER au_academic_advice_trgr AFTER UPDATE ON academic_advice
for each row
begin
INSERT INTO academic_advice_log VALUES (:old.teacher_id ,:old.student_id ,:old.year ,:old.semester,'DELETE' ,DEFAULT ,DEFAULT );
INSERT INTO academic_advice_log VALUES (:new.teacher_id ,:new.student_id ,:new.year ,:new.semester,'INSERT' ,DEFAULT ,DEFAULT );
end;
/
CREATE OR REPLACE TRIGGER ad_academic_advice_trgr AFTER DELETE ON academic_advice
for each row
begin
INSERT INTO academic_advice_log VALUES (:old.teacher_id ,:old.student_id ,:old.year ,:old.semester,'DELETE' ,DEFAULT ,DEFAULT );
end;
/
CREATE TABLE section_log (
section_number NUMBER (3),
course_id VARCHAR2(10) ,
year NUMBER(4) DEFAULT EXTRACT (YEAR FROM sysdate),
semester NUMBER (1),
teacher_id NUMBER(9),
action_name char(6) NOT NULL ,
action_date date DEFAULT sysdate NOT NULL,
action_user VARCHAR2(30) DEFAULT user NOT NULL);
CREATE OR REPLACE TRIGGER ai_section_trgr AFTER INSERT ON section
for each row
begin
INSERT INTO section_log VALUES (:new.section_number ,:new.course_id ,:new.year ,:new.semester ,:new.teacher_id,'INSERT' ,DEFAULT ,DEFAULT );
end;
/
CREATE OR REPLACE TRIGGER au_section_trgr AFTER UPDATE ON section
for each row
begin
INSERT INTO section_log VALUES (:old.section_number ,:old.course_id ,:old.year ,:old.semester ,:old.teacher_id,'DELETE' ,DEFAULT ,DEFAULT );
INSERT INTO section_log VALUES (:new.section_number ,:new.course_id ,:new.year ,:new.semester ,:new.teacher_id,'INSERT' ,DEFAULT ,DEFAULT );
end;
/
CREATE OR REPLACE TRIGGER ad_section_trgr AFTER DELETE ON section
for each row
begin
INSERT INTO section_log VALUES (:old.section_number ,:old.course_id ,:old.year ,:old.semester ,:old.teacher_id,'DELETE' ,DEFAULT ,DEFAULT );
end;
/
CREATE TABLE enroll_log (
student_id NUMBER(9),
course_id VARCHAR2(10) ,
section_number NUMBER(3) ,
year NUMBER(4) DEFAULT EXTRACT (YEAR FROM sysdate),
semester NUMBER(1) ,
grade_mid NUMBER (2) ,
grade_final NUMBER (3),
action_name char(6) NOT NULL ,
action_date date DEFAULT sysdate NOT NULL,
action_user VARCHAR2(30) DEFAULT user NOT NULL);
CREATE OR REPLACE TRIGGER ai_enroll_trgr AFTER INSERT ON enroll
for each row
begin
INSERT INTO enroll_log VALUES (:new.student_id ,:new.course_id ,:new.section_number ,:new.year ,:new.semester ,:new.grade_mid ,:new.grade_final ,'INSERT' ,DEFAULT ,DEFAULT );
end;
/
CREATE OR REPLACE TRIGGER au_enroll_trgr AFTER UPDATE ON enroll
for each row
begin
INSERT INTO enroll_log VALUES (:old.student_id ,:old.course_id ,:old.section_number ,:old.year ,:old.semester ,:old.grade_mid ,:old.grade_final ,'DELETE' ,DEFAULT ,DEFAULT );
INSERT INTO enroll_log VALUES (:new.student_id ,:new.course_id ,:new.section_number ,:new.year ,:new.semester ,:new.grade_mid ,:new.grade_final ,'INSERT' ,DEFAULT ,DEFAULT );
end;
/
CREATE OR REPLACE TRIGGER ad_enroll_trgr AFTER DELETE ON enroll
for each row
begin
INSERT INTO enroll_log VALUES (:old.student_id ,:old.course_id ,:old.section_number ,:old.year ,:old.semester ,:old.grade_mid ,:old.grade_final ,'DELETE' ,DEFAULT ,DEFAULT );
end;
/
CREATE TABLE section_rooms_log (
section_number NUMBER (3) ,
course_id VARCHAR2 (10) ,
year NUMBER(4) DEFAULT EXTRACT (YEAR FROM sysdate),
semester NUMBER (1),
room_number NUMBER (2),
floor_number NUMBER (2),
building_code CHAR (1),
day DATE ,
start_time DATE ,
end_time DATE ,
action_name char(6) NOT NULL ,
action_date date DEFAULT sysdate NOT NULL,
action_user VARCHAR2(30) DEFAULT user NOT NULL);
CREATE OR REPLACE TRIGGER ai_section_rooms_trgr AFTER INSERT ON section_rooms
for each row
begin
INSERT INTO section_rooms_log VALUES (:new.section_number ,:new.course_id ,:new.year ,:new.semester ,:new.room_number,:new.floor_number ,:new.building_code ,:new.day ,:new.start_time ,:new.end_time ,'INSERT' ,DEFAULT ,DEFAULT );
end;
/
CREATE OR REPLACE TRIGGER au_section_rooms_trgr AFTER UPDATE ON section_rooms
for each row
begin
INSERT INTO section_rooms_log VALUES (:old.section_number ,:old.course_id ,:old.year ,:old.semester ,:old.room_number,:old.floor_number ,:old.building_code ,:old.day ,:old.start_time ,:old.end_time ,'DELETE' ,DEFAULT ,DEFAULT );
INSERT INTO section_rooms_log VALUES (:new.section_number ,:new.course_id ,:new.year ,:new.semester ,:new.room_number,:new.floor_number ,:new.building_code ,:new.day ,:new.start_time ,:new.end_time ,'INSERT' ,DEFAULT ,DEFAULT );
end;
/
CREATE OR REPLACE TRIGGER ad_section_rooms_trgr AFTER DELETE ON section_rooms
for each row
begin
INSERT INTO section_rooms_log VALUES (:old.section_number ,:old.course_id ,:old.year ,:old.semester ,:old.room_number,:old.floor_number ,:old.building_code ,:old.day ,:old.start_time ,:old.end_time ,'DELETE' ,DEFAULT ,DEFAULT );
end;
/
CREATE TABLE student_log (
student_id NUMBER(9),
Full_name_ar VARCHAR2(100) ,
Full_name_en VARCHAR2(100) ,
Nationality VARCHAR2(20) ,
national_id NUMBER(9) ,
sex CHAR ,
social_status CHAR ,
guardian_name VARCHAR2(30),
guardian_national_id NUMBER(9),
guardian_relation VARCHAR2(10) ,
birh_place VARCHAR2(10) ,
date_of_birth DATE ,
religion VARCHAR2(20) ,
health_status VARCHAR2(40) ,
mother_name VARCHAR2(30) ,
mother_job VARCHAR2(20) ,
mother_job_desc VARCHAR2(100) ,
father_job VARCHAR2(20) ,
father_job_desc VARCHAR2(100) ,
parents_status VARCHAR2(30) ,
number_of_family_members NUMBER(2) ,
family_university_students NUMBER(2) ,
social_affairs VARCHAR2(40) ,
phone NUMBER(12) ,
telephone_home NUMBER(8) ,
emergency_phone NUMBER(12) ,
email VARCHAR2(30) ,
tawjihi_GPA NUMBER(4,2) ,
tawjihi_field CHAR ,
area_name VARCHAR2(30) ,
city_name VARCHAR2(30) ,
block_name VARCHAR2(30) ,
street_name VARCHAR2(30) ,
major_id NUMBER(3),
balance NUMBER(5) ,
action_name char (6) NOT NULL,
action_date date DEFAULT sysdate NOT NULL,
action_user VARCHAR2(30) DEFAULT user NOT NULL);
CREATE OR REPLACE TRIGGER ai_student_trgr AFTER INSERT ON student
for each row
begin
INSERT INTO student_log VALUES (:new.student_id ,:new.Full_name_ar ,:new.Full_name_en ,:new.Nationality ,:new.national_id ,:new.sex ,:new.social_status ,:new.guardian_name ,:new.guardian_national_id ,:new.guardian_relation ,:new.birh_place ,:new.date_of_birth ,:new.religion,:new.health_status ,:new.mother_name ,:new.mother_job ,:new.mother_job_desc ,:new.father_job ,:new.father_job_desc ,:new.parents_status,:new.number_of_family_members ,:new.family_university_students ,:new.social_affairs ,:new.phone ,:new.telephone_home ,:new.emergency_phone ,:new.email ,:new.tawjihi_GPA ,:new.tawjihi_field ,:new.area_name ,:new.city_name ,:new.block_name ,:new.street_name ,:new.major_id ,:new.balance ,'INSERT' ,DEFAULT ,DEFAULT );
end;
/
CREATE OR REPLACE TRIGGER au_student_trgr AFTER UPDATE ON student
for each row
begin
INSERT INTO student_log VALUES (:old.student_id ,:old.Full_name_ar ,:old.Full_name_en ,:old.nationality ,:old.national_id ,:old.sex ,:old.social_status ,:old.guardian_name ,:old.guardian_national_id ,:old.guardian_relation ,:old.birh_place ,:old.date_of_birth ,:old.religion,:old.health_status ,:old.mother_name ,:old.mother_job ,:old.mother_job_desc ,:old.father_job ,:old.father_job_desc ,:old.parents_status,:old.number_of_family_members ,:old.family_university_students ,:old.social_affairs ,:old.phone ,:old.telephone_home ,:old.emergency_phone ,:old.email , :old.tawjihi_GPA ,:old.tawjihi_field ,:old.area_name ,:old.city_name ,:old.block_name ,:old.street_name ,:old.major_id ,:old.balance ,'DELETE' ,DEFAULT ,DEFAULT );
INSERT INTO student_log VALUES (:new.student_id ,:new.Full_name_ar ,:new.Full_name_en ,:new.nationality ,:new.national_id ,:new.sex ,:new.social_status ,:new.guardian_name ,:new.guardian_national_id ,:new.guardian_relation ,:new.birh_place ,:new.date_of_birth ,:new.religion,:new.health_status ,:new.mother_name ,:new.mother_job ,:new.mother_job_desc ,:new.father_job ,:new.father_job_desc ,:new.parents_status,:new.number_of_family_members ,:new.family_university_students ,:new.social_affairs ,:new.phone ,:new.telephone_home ,:new.emergency_phone ,:new.email , :new.tawjihi_GPA ,:new.tawjihi_field ,:new.area_name ,:new.city_name ,:new.block_name ,:new.street_name , :new.major_id ,:new.balance ,'INSERT' ,DEFAULT ,DEFAULT );
end;
/
CREATE OR REPLACE TRIGGER ad_student_trgr AFTER DELETE ON student
for each row
begin
INSERT INTO student_log VALUES (:old.student_id ,:old.Full_name_ar ,:old.Full_name_en ,:old.nationality ,:old.national_id ,:old.sex ,:old.social_status ,:old.guardian_name ,:old.guardian_national_id ,:old.guardian_relation ,:old.birh_place ,:old.date_of_birth ,:old.religion,:old.health_status ,:old.mother_name ,:old.mother_job ,:old.mother_job_desc ,:old.father_job ,:old.father_job_desc ,:old.parents_status,:old.number_of_family_members ,:old.family_university_students ,:old.social_affairs ,:old.phone ,:old.telephone_home ,:old.emergency_phone ,:old.email ,:old.tawjihi_GPA ,:old.tawjihi_field ,:old.area_name ,:old.city_name ,:old.block_name ,:old.street_name , :old.major_id , :old.balance ,'DELETE' ,DEFAULT ,DEFAULT );
end;
/
CREATE TABLE Nationality_log(
Nationality VARCHAR2(20),
action_name char(6) NOT NULL ,
action_date date DEFAULT sysdate NOT NULL,
action_user VARCHAR2(30) DEFAULT user NOT NULL);
CREATE OR REPLACE TRIGGER ai_Nationality_trgr AFTER INSERT ON Nationality
for each row
begin
INSERT INTO Nationality_log VALUES (:new.Nationality ,'INSERT' ,DEFAULT,DEFAULT );
end;
/
CREATE OR REPLACE TRIGGER au_Nationality_trgr AFTER UPDATE ON Nationality
for each row
begin
INSERT INTO Nationality_log VALUES (:old.Nationality ,'DELETE' ,DEFAULT,DEFAULT );
INSERT INTO Nationality_log VALUES (:new.Nationality ,'INSERT' ,DEFAULT,DEFAULT );
end;
/
CREATE OR REPLACE TRIGGER ad_Nationality_trgr AFTER DELETE ON Nationality