Assignment :-
Assign. Name:-Use of Delete,Insert and Update Command.
CLASS:-T.Y.B.Sc. (Compute Science)
Assign. Name:-Use of Delete,Insert and Update Command.
CLASS:-T.Y.B.Sc. (Compute Science)
************************************************************
Delete Command:-
This is used to delete the touple.We can not delete values on only particular attribute, we have to delete complete records.
Syntax:-
Delete from table name
[Where condition];
Example:-
Delete all records where account number of depositer is 786
CUST_NAME ACC_NO
----------------------- ---------------------
Samir 770
Mahesh 998
Smita 443
Vikas 112
Sachin 89
Vaibhav 786
Answer:-
SQL>delete from depositer where acc_no='786';
1 row deleted.
SQL>select * from depositer;
CUST_NAME ACC_NO
----------------------- ---------------------
Samir 770
Mahesh 998
Smita 443
Vikas 112
Sachin 89
SQL>delete from borrower
2 where loan_no BETWEEN 3 AND 5;
3 row deleted.
SQL>select * from borrower;
CUST_NAME LOAN_NO
--------------- -----------------
Samir 1
Mahesh 2
Vaibhav 6
Update Command:-
In some situations,we may wish to change a value in touple without changing all value in touple. For this purpose, update statement can be used.
Syntax:-
Update table name
SET column name =expression
[Where condition];
Example:-
Update all the branches with increase of 5% annual interest.
ACC_NO BNAME BALANCE
----------- ---------------- ----------------
770 M G ROAD 10000
998 F C ROAD 5000
443 G P ROAD 2000
112 M G ROAD 15000
89 G P ROAD 20000
786 F C ROAD 4000
Answer:-
SQL>update account
2 SET balance=balance*1.05;
6 row created.
SQL>select * from account;
ACC_NO BNAME BALANCE
----------- --------------- ----------------
770 M G ROAD 10500
998 F C ROAD 5250
443 G P ROAD 2100
112 M G ROAD 15750
89 G P ROAD 21000
786 F C ROAD 4200
6 row selected.
Delete Command:-
This is used to delete the touple.We can not delete values on only particular attribute, we have to delete complete records.
Syntax:-
Delete from table name
[Where condition];
Example:-
Delete all records where account number of depositer is 786
CUST_NAME ACC_NO
----------------------- ---------------------
Samir 770
Mahesh 998
Smita 443
Vikas 112
Sachin 89
Vaibhav 786
Answer:-
SQL>delete from depositer where acc_no='786';
1 row deleted.
SQL>select * from depositer;
CUST_NAME ACC_NO
----------------------- ---------------------
Samir 770
Mahesh 998
Smita 443
Vikas 112
Sachin 89
SQL>delete from borrower
2 where loan_no BETWEEN 3 AND 5;
3 row deleted.
SQL>select * from borrower;
CUST_NAME LOAN_NO
--------------- -----------------
Samir 1
Mahesh 2
Vaibhav 6
Update Command:-
In some situations,we may wish to change a value in touple without changing all value in touple. For this purpose, update statement can be used.
Syntax:-
Update table name
SET column name =expression
[Where condition];
Example:-
Update all the branches with increase of 5% annual interest.
ACC_NO BNAME BALANCE
----------- ---------------- ----------------
770 M G ROAD 10000
998 F C ROAD 5000
443 G P ROAD 2000
112 M G ROAD 15000
89 G P ROAD 20000
786 F C ROAD 4000
Answer:-
SQL>update account
2 SET balance=balance*1.05;
6 row created.
SQL>select * from account;
ACC_NO BNAME BALANCE
----------- --------------- ----------------
770 M G ROAD 10500
998 F C ROAD 5250
443 G P ROAD 2100
112 M G ROAD 15750
89 G P ROAD 21000
786 F C ROAD 4200
6 row selected.
No comments:
Post a Comment