-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignment-14.sql
More file actions
62 lines (56 loc) · 1.28 KB
/
Assignment-14.sql
File metadata and controls
62 lines (56 loc) · 1.28 KB
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
Create database assign14;
use assign14;
--Q4. Do the following:
--A. Create a table with columns: Name, Math_marks, English_marks, Physics_marks, Total, Average.
Create table Student(Name Varchar(20),Math_Marks int,English_marks Int, Physics_marks int , Total int, Average Float);
--B. Create a trigger which inserts logs into an audit table when you insert and delete records from the
--above table
Create Table Student_Audit (
Name Varchar(20),
Math_Marks int,
English_marks Int,
Physics_marks int,
Total int,
Average Float,
Updated_at Datetime,
Operation char(3));
Create trigger audit
on Student
After Insert, Delete
as
Begin
Insert into Student_Audit(
Name,
Math_Marks,
English_marks,
Physics_marks,
Total,
Average,
Updated_at,
Operation)
Select
Name,
Math_Marks,
English_marks,
Physics_marks,
Total,
Average,
GETDATE(),
'INS'
From Inserted
Union All
Select
Name,
Math_Marks,
English_marks,
Physics_marks,
Total,
Average,
GETDATE(),
'Del'
From deleted;
End;
Insert into Student Values('Vaishi',11,12,20,12,12);
select * from Student
select * from Student_Audit
Delete from Student where Name = 'Vaishi';