Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

DBMS LAB

242 views

Published on

Published in: Education
  • Be the first to comment

  • Be the first to like this

DBMS LAB

  1. 1. LAB – 4create table item(itemcode number, itemname varchar(20), price number(10,2), primarykey(itemcode));Table created.SQL> desc item;Name Null? Type----------------------------------------- -------- ----------------------------ITEMCODE NOT NULL NUMBERITEMNAME VARCHAR2(20)PRICE NUMBER(10,2)create table purchase(itemcode number, qty number, foreign key(itemcode) referencesitem(itemcode));Table created.SQL> desc purchase;Name Null? Type----------------------------------------- -------- ----------------------------ITEMCODE NUMBERQTY NUMBERSQL> insert into item values(&itemcode,&itemname,&price);Enter value for itemcode: 001Enter value for itemname: tea_powderEnter value for price: 25old 1: insert into item values(&itemcode,&itemname,&price)
  2. 2. new 1: insert into item values(001,tea_powder,25)1 row created.SQL> /Enter value for itemcode: 002Enter value for itemname: coffee_powderEnter value for price: 40old 1: insert into item values(&itemcode,&itemname,&price)new 1: insert into item values(002,coffee_powder,40)1 row created.SQL> /Enter value for itemcode: 003Enter value for itemname: dove_soapEnter value for price: 49old 1: insert into item values(&itemcode,&itemname,&price)new 1: insert into item values(003,dove_soap,49)1 row created.SQL> /Enter value for itemcode: 004Enter value for itemname: clinicplus
  3. 3. Enter value for price: 10old 1: insert into item values(&itemcode,&itemname,&price)new 1: insert into item values(004,clinicplus,10)1 row created.SQL> /Enter value for itemcode: 005Enter value for itemname: chilly_powderEnter value for price: 15old 1: insert into item values(&itemcode,&itemname,&price)new 1: insert into item values(005,chilly_powder,15)1 row created.SQL> /Enter value for itemcode: 006Enter value for itemname: fair&lovelyEnter value for price: 40old 1: insert into item values(&itemcode,&itemname,&price)new 1: insert into item values(006,fair&lovely,40)1 row created.SQL> /
  4. 4. Enter value for itemcode: 007Enter value for itemname: riceEnter value for price: 30old 1: insert into item values(&itemcode,&itemname,&price)new 1: insert into item values(007,rice,30)1 row created.SQL> select * from item; ITEMCODE ITEMNAME PRICE---------- -------------------- ---------- 1 tea_powder 25 2 coffee_powder 40 3 dove_soap 49 4 clinicplus 10 5 chilly_powder 15 6 fair&lovely 40 7 rice 307 rows selected.SQL> insert into purchase values(&itemcode,&qty);Enter value for itemcode: 001Enter value for qty: 0
  5. 5. old 1: insert into purchase values(&itemcode,&qty)new 1: insert into purchase values(001,0)1 row created.SQL> /Enter value for itemcode: 002Enter value for qty: 2old 1: insert into purchase values(&itemcode,&qty)new 1: insert into purchase values(002,2)1 row created.SQL> /Enter value for itemcode: 003Enter value for qty: 1old 1: insert into purchase values(&itemcode,&qty)new 1: insert into purchase values(003,1)1 row created.SQL> /Enter value for itemcode: 004Enter value for qty: 5old 1: insert into purchase values(&itemcode,&qty)
  6. 6. new 1: insert into purchase values(004,5)1 row created.SQL> /Enter value for itemcode: 005Enter value for qty: 0old 1: insert into purchase values(&itemcode,&qty)new 1: insert into purchase values(005,0)1 row created.SQL> /Enter value for itemcode: 007Enter value for qty: 1old 1: insert into purchase values(&itemcode,&qty)new 1: insert into purchase values(007,1)1 row created.SQL> /Enter value for itemcode: 006Enter value for qty: 2old 1: insert into purchase values(&itemcode,&qty)new 1: insert into purchase values(006,2)
  7. 7. 1 row created.SQL> select * from purchase; ITEMCODE QTY---------- ---------- 1 0 2 2 3 1 4 5 5 0 7 1 6 27 rows selected.SQL> select itemcode,itemname from item where itemcode in(select itemcode from purchase whereqty!=0);ITEMCODE ITEMNAME---------- -------------------- 2 coffee_powder 3 dove_soap 4 clinicplus 6 fair&lovely 7 rice
  8. 8. SQL> select itemcode,itemname from item where itemcode in(select itemcode from purchase whereqty=0);ITEMCODE ITEMNAME---------------------------------------- 1 Tea_powder 2 Chilly_powderSQL>select i.tem_code,p.item_name,p.qty from item I,purchase p where i.item_code=p.item_code;Select sum(item_code)total_items_purchased from purchase;SQL>Commit;Commit complete.

×