Tuesday, 11 February 2014

ALTER, UPDATE AND DELETE COMMANDS IN SQL


SQL>  create table product(Pid int primary key,pname varchar (30),Price int);

Table created.

SQL> insert into product values(1,'Monitor',6000);

1 row created.

SQL> insert into product values(2,'Mouse',200);

1 row created.

SQL> insert into product values(3,'Keyboard',500);

1 row created.

SQL> insert into product values(4,'Printer',6500);

1 row created.

SQL> alter table product
  2  add(Qty int);

Table altered.

SQL> select * from product;

       PID PNAME                               PRICE        QTY
---------- ------------------------------ ---------- ----------
         1 Monitor                              6000
         2 Mouse                                 200
         3 Keyboard                            500
         4 Printer                                 6500

SQL> update product set qty=2 where Pname='Mouse';

1 row updated.

SQL> select * from product;

       PID PNAME                               PRICE        QTY
---------- ----------------------------   ---------- ----------
         1 Monitor                              6000
         2 Mouse                                 200          2
         3 Keyboard                            500
         4 Printer                                 6500

SQL> delete from product where pid=2 and Qty=2;

1 row deleted.

SQL> select * from product;

       PID PNAME                               PRICE        QTY
---------- ------------------------------ ---------- ----------
         1 Monitor                              6000
         3 Keyboard                            500
         4 Printer                                6500

SQL> commit;

Commit complete.




No comments:

Post a Comment