Update OS/bash/Week4/SQLPlus.md

This commit is contained in:
Aadit Agrawal 2025-01-21 15:38:19 +05:30
parent 01755843a4
commit 007e7d7b5e

View File

@ -366,7 +366,7 @@ DRIVER_ID# REGNO REPORT_NUMBER DAMAGE_AMOUNT
1238 HFSP5601 5 1500
1238 HFSP5601 12 95500
```
## Q3
Updating data entries:
```sql
SQL> update participated set damage_amount=25000 where regno='HFSP5601' and report_number=12;
@ -387,6 +387,8 @@ DRIVER_ID# REGNO REPORT_NUMBER DAMAGE_AMOUNT
1238 HFSP5601 5 1500
1238 HFSP5601 12 25000
```
## Q4
### Dropping an attribute
```sql
SQL> alter table Participated
@ -416,3 +418,59 @@ SQL> alter table Participated
Table altered.
```
### Conditional Deletion
```sql
SQL> select * from accident;
REPORT_NUMBER ACCD_DATE LOCATION
------------- --------- --------------------------------------------------
1 01-JAN-24 Delhi India
3 29-FEB-24 India
4 11-OCT-93 Daman and Diu India
5 31-MAR-00 Gujrat India
12 17-JUL-00 karnataka India
SQL > delete from accident where extract(year from accd_date)=1993;
1 row deleted.
SQL> select * from accident;
REPORT_NUMBER ACCD_DATE LOCATION
------------- --------- --------------------------------------------------
1 01-JAN-24 Delhi India
3 29-FEB-24 India
5 31-MAR-00 Gujrat India
12 17-JUL-00 karnataka India
```
## Q5
```sql
SQL> alter table Participated drop constraint fkey3participated;
Table altered.
SQL> alter table Participated add constraint fkey3participated foreign key(report_number) references accident(report_number) on delete cascade;
Table altered.
```
## Q6
```sql
SQL> alter table participated add constraint checkparticipated check(Damage_amount>=0);
Table altered.
SQL> select * from participated;
DRIVER_ID# REGNO REPORT_NUMBER DAMAGE_AMOUNT
------------------------------ -------------------- ------------- -------------
1234 ABCD0001 1 10000
1236 DSDS0001 3 150
1238 HFSP5601 5 1500
1238 HFSP5601 12 25000
```