Update DBMS/SQL/Week7/writeup.md
This commit is contained in:
parent
2bd895d3bf
commit
5a67380e0c
1 changed files with 6 additions and 2 deletions
|
@ -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.`
|
### 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
|
||||||
SQL> CREATE OR REPLACE TRIGGER update_total_damage
|
SQL> CREATE OR REPLACE TRIGGER update_total_damage
|
||||||
2 AFTER
|
2 AFTER
|
||||||
|
@ -62,9 +62,11 @@ SQL> CREATE OR REPLACE TRIGGER update_total_damage
|
||||||
|
|
||||||
Trigger created.
|
Trigger created.
|
||||||
```
|
```
|
||||||
|
Adding an identifier `total_damage`:
|
||||||
```sql
|
```sql
|
||||||
SQL> ALTER TABLE ACCIDENT ADD total_damage NUMBER;
|
SQL> ALTER TABLE ACCIDENT ADD total_damage NUMBER;
|
||||||
```
|
```
|
||||||
|
Test case with Insertion:
|
||||||
```sql
|
```sql
|
||||||
SQL> INSERT INTO
|
SQL> INSERT INTO
|
||||||
PARTICIPATED (driver_id#, regno, report_number, damage_amount)
|
PARTICIPATED (driver_id#, regno, report_number, damage_amount)
|
||||||
|
@ -84,7 +86,9 @@ SQL> SELECT
|
||||||
REPORT_NUMBER TOTAL_DAMAGE
|
REPORT_NUMBER TOTAL_DAMAGE
|
||||||
------------- ------------
|
------------- ------------
|
||||||
1 15000
|
1 15000
|
||||||
|
```
|
||||||
|
Test case with Deletion:
|
||||||
|
```sql
|
||||||
SQL> DELETE FROM PARTICIPATED
|
SQL> DELETE FROM PARTICIPATED
|
||||||
WHERE
|
WHERE
|
||||||
driver_id# = '1235'
|
driver_id# = '1235'
|
||||||
|
|
Loading…
Add table
Reference in a new issue