Update OS/bash/Week4/SQLPlus.md

This commit is contained in:
Aadit Agrawal 2025-01-21 15:28:23 +05:30
parent e74ab36f1b
commit 01755843a4

View File

@ -334,4 +334,85 @@ Note:
```sql
SQL> @<FILEPATH>/filename.sql
```
will import the commands from a doc and run them.
will import the commands from a doc and run them.
Saved commands into `participated.sql`.
```sql
SQL> @C:\Users\student\Downloads\participated.sql
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
SQL> select * from participated;
DRIVER_ID# REGNO REPORT_NUMBER DAMAGE_AMOUNT
------------------------------ -------------------- ------------- -------------
1234 ABCD0001 1 10000
1236 DSDS0001 3 150
1237 ABCD4001 4 799
1238 HFSP5601 5 1500
1238 HFSP5601 12 95500
```
Updating data entries:
```sql
SQL> update participated set damage_amount=25000 where regno='HFSP5601' and report_number=12;
1 row updated.
SQL> update participated set damage_amount=25000 where regno='ABCD0001' and report_number=12;
0 rows updated.
SQL> select * from participated;
DRIVER_ID# REGNO REPORT_NUMBER DAMAGE_AMOUNT
------------------------------ -------------------- ------------- -------------
1234 ABCD0001 1 10000
1236 DSDS0001 3 150
1237 ABCD4001 4 799
1238 HFSP5601 5 1500
1238 HFSP5601 12 25000
```
### Dropping an attribute
```sql
SQL> alter table Participated
2 drop constraint fkey3paricipated;
Table altered.
SQL> select * from participated;
DRIVER_ID# REGNO REPORT_NUMBER DAMAGE_AMOUNT
------------------------------ -------------------- ------------- -------------
1234 ABCD0001 1 10000
1236 DSDS0001 3 150
1237 ABCD4001 4 799
1238 HFSP5601 5 1500
1238 HFSP5601 12 25000
```
Adding back the attribute.
```sql
SQL> alter table Participated
2 add constraint fkey3participated foreign key(report_number) references accident(report_number)
3 on delete cascade;
Table altered.
```