Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
4.1 kB
13
Indexable
Never
06/03/2024
=====================================================================================================
Update statement:
the update statement is used for modify the existing records.

syntax:-update tablename set column_name=values where condition.

use testdb;
select * from person;
update person set age=35 where p_id=4;
update person set age =24

Note: If you omit the where clause all records in the table will be updated.


================================================================================================

differance alter and update:
alter:1. data defination lang(DDL)
      2.alter command will perform structure level.
      3.syntax alter table tablename (modify/add/rename) Drop column column_name
      4. this command make changes with the table structure.
      5. alter command works on columns


update:1. data manipulation lang(DML)
       2.update command will perform on data level.
       3 syntax :-update table_name set column_name=values
       4. this command make changes the data inside table.
        5. update cammand works on perticular rows in the table

===============================================================================================

Delete statement:-
delete statement is use for delete the existing records in the table .
syntax:-delete from tablename where condition

exa:-
delete from pesron where Pname="tina"
------------------------------------------------------------------

difference between truncate and delete

delete:-1. It is DML command
        2.delete command is  use where clause.
        3.delete operations can be rolled back
        4.delete command is slower than truncate command.
        5. the delete command is used to delete the specific rows(as per condition)

truncate:-1. It is DDL command
         2. In truncate command we are not use where clause
         3. truncate can not be rolled back
         4. truncate command is faster than delete command
         5. truncte command is used to delete all rows from the table.

Note: If you omit the where clause all records in the table will be deleted.

=========================================================================================================
commit and rollback

commit :-
commiot in sql is used for permanantly save the changes.

rollback:
rollback command is used for undo the trasactional data that have not saved in the database.

select * from customerinfo;
update customerinfo set addr="pune" where cust_id=101;
commit;
update customerinfo set addr="nanded" where cust_id=104;

update customerinfo set addr="mumbai" where cust_id=106;

rollback;


select * from customerinfo;
delete from customerinfo ;
rollback;

truncate table customerinfo;
rollback;

=========================================================================================================================
assignment:-

Q1.From the following table, write a SQL query to find the maximum order (purchase) amount for each customer. 
The customer ID should be in the range 3002 and 3007(Begin and end values are included.).
Filter the rows for maximum order (purchase) amount is higher than 1000. 
Return customer id and maximum purchase amount.

Sample table: orders

ord_no      purch_amt   ord_date    customer_id  salesman_id
----------  ----------  ----------  -----------  -----------
70001       150.5       2012-10-05  3005         5002
70009       270.65      2012-09-10  3001         5005
70002       65.26       2012-10-05  3002         5001
70004       110.5       2012-08-17  3009         5003
70007       948.5       2012-09-10  3005         5002
70005       2400.6      2012-07-27  3007         5001
70008       5760        2012-09-10  3002         5001
70010       1983.43     2012-10-10  3004         5006
70003       2480.4      2012-10-10  3009         5003
70012       250.45      2012-06-27  3008         5002
70011       75.29       2012-08-17  3003         5007
70013       3045.6      2012-04-25  3002         5001

Leave a Comment