Update DBMS/SQL/Week7/writeup.md

This commit is contained in:
Aadit Agrawal 2025-02-18 15:07:22 +05:30
parent 2bd895d3bf
commit 5a67380e0c

View file

@ -42,7 +42,7 @@ Driver_id: 1235 Name: Rohit Address: Banglalore India
```
### Q2. Create a trigger that updates a `total_damage` column in the `accident` table whenever a new entry is added to or removed from the participated field.`
Trigger:
```SQL
SQL> CREATE OR REPLACE TRIGGER update_total_damage
2 AFTER
@ -62,9 +62,11 @@ SQL> CREATE OR REPLACE TRIGGER update_total_damage
Trigger created.
```
Adding an identifier `total_damage`:
```sql
SQL> ALTER TABLE ACCIDENT ADD total_damage NUMBER;
```
Test case with Insertion:
```sql
SQL> INSERT INTO
PARTICIPATED (driver_id#, regno, report_number, damage_amount)
@ -84,7 +86,9 @@ SQL> SELECT
REPORT_NUMBER TOTAL_DAMAGE
------------- ------------
1 15000
```
Test case with Deletion:
```sql
SQL> DELETE FROM PARTICIPATED
WHERE
driver_id# = '1235'