DBMS LAB

118
-1

Published on

Published in: Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
118
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

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.

×