SlideShare a Scribd company logo
LAB – 4
create table item(itemcode number, itemname varchar(20), price number(10,2), primary
key(itemcode));

Table created.

SQL> desc item;

Name                                Null?            Type

----------------------------------------- -------- ----------------------------

ITEMCODE                               NOT           NULL NUMBER

ITEMNAME                                             VARCHAR2(20)

PRICE                                                NUMBER(10,2)



create table purchase(itemcode number, qty number, foreign key(itemcode) references
item(itemcode));

Table created.

SQL> desc purchase;

Name                                Null?            Type

----------------------------------------- -------- ----------------------------

ITEMCODE                                             NUMBER

QTY                                                  NUMBER



SQL> insert into item values('&itemcode','&itemname','&price');

Enter value for itemcode: 001

Enter value for itemname: tea_powder

Enter value for price: 25

old 1: insert into item values('&itemcode','&itemname','&price')
new 1: insert into item values('001','tea_powder','25')



1 row created.



SQL> /

Enter value for itemcode: 002

Enter value for itemname: coffee_powder

Enter value for price: 40

old 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: 003

Enter value for itemname: dove_soap

Enter value for price: 49

old 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: 004

Enter value for itemname: clinicplus
Enter value for price: 10

old 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: 005

Enter value for itemname: chilly_powder

Enter value for price: 15

old 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: 006

Enter value for itemname: fair&lovely

Enter value for price: 40

old 1: insert into item values('&itemcode','&itemname','&price')

new 1: insert into item values('006','fair&lovely','40')



1 row created.



SQL> /
Enter value for itemcode: 007

Enter value for itemname: rice

Enter value for price: 30

old 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                      30



7 rows selected.



SQL> insert into purchase values('&itemcode','&qty');

Enter value for itemcode: 001

Enter value for qty: 0
old 1: insert into purchase values('&itemcode','&qty')

new 1: insert into purchase values('001','0')



1 row created.



SQL> /

Enter value for itemcode: 002

Enter value for qty: 2

old 1: insert into purchase values('&itemcode','&qty')

new 1: insert into purchase values('002','2')



1 row created.



SQL> /

Enter value for itemcode: 003

Enter value for qty: 1

old 1: insert into purchase values('&itemcode','&qty')

new 1: insert into purchase values('003','1')



1 row created.



SQL> /

Enter value for itemcode: 004

Enter value for qty: 5

old 1: insert into purchase values('&itemcode','&qty')
new 1: insert into purchase values('004','5')



1 row created.



SQL> /

Enter value for itemcode: 005

Enter value for qty: 0

old 1: insert into purchase values('&itemcode','&qty')

new 1: insert into purchase values('005','0')



1 row created.



SQL> /

Enter value for itemcode: 007

Enter value for qty: 1

old 1: insert into purchase values('&itemcode','&qty')

new 1: insert into purchase values('007','1')



1 row created.



SQL> /

Enter value for itemcode: 006

Enter value for qty: 2

old 1: insert into purchase values('&itemcode','&qty')

new 1: insert into purchase values('006','2')
1 row created.



SQL> select * from purchase;



 ITEMCODE               QTY

---------- ----------

      1                 0

      2                 2

      3                 1

      4                 5

      5                 0

      7                 1

      6                 2



7 rows selected.

SQL> select itemcode,itemname from item where itemcode in(select itemcode from purchase where
qty!=0);

ITEMCODE                ITEMNAME

---------- --------------------

      2                 coffee_powder

      3                 dove_soap

      4                 clinicplus

      6                 fair&lovely

      7                 rice
SQL> select itemcode,itemname from item where itemcode in(select itemcode from purchase where
qty=0);

ITEMCODE             ITEMNAME

----------------------------------------

     1                    Tea_powder
     2                    Chilly_powder



SQL>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.

More Related Content

PPTX
Geek Sync | Rewriting Bad SQL Code 101
PDF
Check Constraint In MySQL 8.0
PPT
PHP cart
PDF
Avoiding cursors with sql server 2005 tech republic
PPTX
Execution plans for mere mortals
PPT
08 Queries
DOC
Database management system file
ODP
Chetan postgresql partitioning
Geek Sync | Rewriting Bad SQL Code 101
Check Constraint In MySQL 8.0
PHP cart
Avoiding cursors with sql server 2005 tech republic
Execution plans for mere mortals
08 Queries
Database management system file
Chetan postgresql partitioning

What's hot (20)

PDF
Dealing with Legacy PHP Applications
PDF
PPTX
CocoaHeads Moscow. Азиз Латыпов, VIPole. «Запросы в CoreData с агрегатными фу...
PDF
Contagion的Ruby/Rails投影片
 
PPTX
Typed? Dynamic? Both! Cross-platform DSLs in C#
PDF
The Ring programming language version 1.9 book - Part 95 of 210
PPTX
The secret unit testing tools no one has ever told you about
TXT
DOC
code for quiz in my sql
PDF
Hidden rocks in Oracle ADF
PDF
Asynchronous JS in Odoo
PDF
Leveraging Symfony2 Forms
PDF
Everything you always wanted to know about forms* *but were afraid to ask
PDF
PHPUnit Episode iv.iii: Return of the tests
PDF
PHPunit and you
PDF
Mpg Dec07 Gian Lorenzetto
KEY
Postgres rules
PDF
Mastering Oracle ADF Bindings
PDF
How to Create a l10n Payroll Structure
PPT
Os Nixon
Dealing with Legacy PHP Applications
CocoaHeads Moscow. Азиз Латыпов, VIPole. «Запросы в CoreData с агрегатными фу...
Contagion的Ruby/Rails投影片
 
Typed? Dynamic? Both! Cross-platform DSLs in C#
The Ring programming language version 1.9 book - Part 95 of 210
The secret unit testing tools no one has ever told you about
code for quiz in my sql
Hidden rocks in Oracle ADF
Asynchronous JS in Odoo
Leveraging Symfony2 Forms
Everything you always wanted to know about forms* *but were afraid to ask
PHPUnit Episode iv.iii: Return of the tests
PHPunit and you
Mpg Dec07 Gian Lorenzetto
Postgres rules
Mastering Oracle ADF Bindings
How to Create a l10n Payroll Structure
Os Nixon
Ad

Viewers also liked (11)

PPTX
Марина Цветаева
PPTX
досвід роботи
PPTX
Восточные лакомства
PPTX
The 6 biggest mistakes of golf instructors
PDF
Up Close with Mayor Dave Bing
PPT
Biologia odola
DOCX
Cost element categories
PPTX
досвід роботи н. с.
DOCX
Guru panas baran (teori realiti)
PDF
10 Steps to Product Market Fit - Japanese Translation
PPTX
Opportunity analysis (2)
Марина Цветаева
досвід роботи
Восточные лакомства
The 6 biggest mistakes of golf instructors
Up Close with Mayor Dave Bing
Biologia odola
Cost element categories
досвід роботи н. с.
Guru panas baran (teori realiti)
10 Steps to Product Market Fit - Japanese Translation
Opportunity analysis (2)
Ad

Similar to DBMS LAB (20)

TXT
SQL QUERY PRACTICE
DOCX
Use this script for the assignment.Please follow instructions as t.docx
DOCX
EJERCICIOS DE BENFORTAN
PDF
Common SQL Programming Mistakes
PPT
SQL structure query language full presentation
DOC
Sql queries
PPTX
Database Management Systems and SQL SERVER Multiple tablees.pptx
DOC
Onlin shopping
PDF
Inventory management system
PDF
lab.123456789123456789123456789123456789
 
PPTX
Database Management Systems and SQL SERVER Multiple tables [Autosaved].pptx
PPT
1 introduction to my sql
DOCX
9)creating simple query
PPTX
SQL intro.pptx
DOC
Purpose of project web based billing system
PPTX
Practical guide to SQL basics
DOC
Create table dimcustomer ( customerid int/tutorialoutlet
PPSX
IM01: Business Intelligence
SQL QUERY PRACTICE
Use this script for the assignment.Please follow instructions as t.docx
EJERCICIOS DE BENFORTAN
Common SQL Programming Mistakes
SQL structure query language full presentation
Sql queries
Database Management Systems and SQL SERVER Multiple tablees.pptx
Onlin shopping
Inventory management system
lab.123456789123456789123456789123456789
 
Database Management Systems and SQL SERVER Multiple tables [Autosaved].pptx
1 introduction to my sql
9)creating simple query
SQL intro.pptx
Purpose of project web based billing system
Practical guide to SQL basics
Create table dimcustomer ( customerid int/tutorialoutlet
IM01: Business Intelligence

Recently uploaded (20)

PDF
Practical Manual AGRO-233 Principles and Practices of Natural Farming
PDF
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
PPTX
A powerpoint presentation on the Revised K-10 Science Shaping Paper
PPTX
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
PDF
advance database management system book.pdf
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PDF
1.3 FINAL REVISED K-10 PE and Health CG 2023 Grades 4-10 (1).pdf
PDF
AI-driven educational solutions for real-life interventions in the Philippine...
PPTX
Computer Architecture Input Output Memory.pptx
PPTX
Introduction to pro and eukaryotes and differences.pptx
PDF
FORM 1 BIOLOGY MIND MAPS and their schemes
PDF
Empowerment Technology for Senior High School Guide
PDF
Trump Administration's workforce development strategy
PDF
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PDF
Weekly quiz Compilation Jan -July 25.pdf
PDF
Vision Prelims GS PYQ Analysis 2011-2022 www.upscpdf.com.pdf
PDF
CISA (Certified Information Systems Auditor) Domain-Wise Summary.pdf
DOC
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
Practical Manual AGRO-233 Principles and Practices of Natural Farming
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
A powerpoint presentation on the Revised K-10 Science Shaping Paper
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
advance database management system book.pdf
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
1.3 FINAL REVISED K-10 PE and Health CG 2023 Grades 4-10 (1).pdf
AI-driven educational solutions for real-life interventions in the Philippine...
Computer Architecture Input Output Memory.pptx
Introduction to pro and eukaryotes and differences.pptx
FORM 1 BIOLOGY MIND MAPS and their schemes
Empowerment Technology for Senior High School Guide
Trump Administration's workforce development strategy
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
Weekly quiz Compilation Jan -July 25.pdf
Vision Prelims GS PYQ Analysis 2011-2022 www.upscpdf.com.pdf
CISA (Certified Information Systems Auditor) Domain-Wise Summary.pdf
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf

DBMS LAB

  • 1. LAB – 4 create table item(itemcode number, itemname varchar(20), price number(10,2), primary key(itemcode)); Table created. SQL> desc item; Name Null? Type ----------------------------------------- -------- ---------------------------- ITEMCODE NOT NULL NUMBER ITEMNAME VARCHAR2(20) PRICE NUMBER(10,2) create table purchase(itemcode number, qty number, foreign key(itemcode) references item(itemcode)); Table created. SQL> desc purchase; Name Null? Type ----------------------------------------- -------- ---------------------------- ITEMCODE NUMBER QTY NUMBER SQL> insert into item values('&itemcode','&itemname','&price'); Enter value for itemcode: 001 Enter value for itemname: tea_powder Enter value for price: 25 old 1: insert into item values('&itemcode','&itemname','&price')
  • 2. new 1: insert into item values('001','tea_powder','25') 1 row created. SQL> / Enter value for itemcode: 002 Enter value for itemname: coffee_powder Enter value for price: 40 old 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: 003 Enter value for itemname: dove_soap Enter value for price: 49 old 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: 004 Enter value for itemname: clinicplus
  • 3. Enter value for price: 10 old 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: 005 Enter value for itemname: chilly_powder Enter value for price: 15 old 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: 006 Enter value for itemname: fair&lovely Enter value for price: 40 old 1: insert into item values('&itemcode','&itemname','&price') new 1: insert into item values('006','fair&lovely','40') 1 row created. SQL> /
  • 4. Enter value for itemcode: 007 Enter value for itemname: rice Enter value for price: 30 old 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 30 7 rows selected. SQL> insert into purchase values('&itemcode','&qty'); Enter value for itemcode: 001 Enter value for qty: 0
  • 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: 002 Enter value for qty: 2 old 1: insert into purchase values('&itemcode','&qty') new 1: insert into purchase values('002','2') 1 row created. SQL> / Enter value for itemcode: 003 Enter value for qty: 1 old 1: insert into purchase values('&itemcode','&qty') new 1: insert into purchase values('003','1') 1 row created. SQL> / Enter value for itemcode: 004 Enter value for qty: 5 old 1: insert into purchase values('&itemcode','&qty')
  • 6. new 1: insert into purchase values('004','5') 1 row created. SQL> / Enter value for itemcode: 005 Enter value for qty: 0 old 1: insert into purchase values('&itemcode','&qty') new 1: insert into purchase values('005','0') 1 row created. SQL> / Enter value for itemcode: 007 Enter value for qty: 1 old 1: insert into purchase values('&itemcode','&qty') new 1: insert into purchase values('007','1') 1 row created. SQL> / Enter value for itemcode: 006 Enter value for qty: 2 old 1: insert into purchase values('&itemcode','&qty') new 1: insert into purchase values('006','2')
  • 7. 1 row created. SQL> select * from purchase; ITEMCODE QTY ---------- ---------- 1 0 2 2 3 1 4 5 5 0 7 1 6 2 7 rows selected. SQL> select itemcode,itemname from item where itemcode in(select itemcode from purchase where qty!=0); ITEMCODE ITEMNAME ---------- -------------------- 2 coffee_powder 3 dove_soap 4 clinicplus 6 fair&lovely 7 rice
  • 8. SQL> select itemcode,itemname from item where itemcode in(select itemcode from purchase where qty=0); ITEMCODE ITEMNAME ---------------------------------------- 1 Tea_powder 2 Chilly_powder SQL>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.