0% found this document useful (0 votes)
126 views7 pages

Case Let 1

This document contains the SQL code to create multiple tables (Programmer, Weather, Book, Supplier, Customer, Items, Orders) and insert data into them. It also includes some sample queries on these tables to retrieve, update, delete and join data between the tables. The tables contain information about programmers, weather data of cities, book details, supplier details, customer details, inventory items details and customer orders.

Uploaded by

Akash Shah
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
126 views7 pages

Case Let 1

This document contains the SQL code to create multiple tables (Programmer, Weather, Book, Supplier, Customer, Items, Orders) and insert data into them. It also includes some sample queries on these tables to retrieve, update, delete and join data between the tables. The tables contain information about programmers, weather data of cities, book details, supplier details, customer details, inventory items details and customer orders.

Uploaded by

Akash Shah
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 7

CREATE TABLE PROGRAMMER

(
EMP_NO NUMBER(5) CONSTRAINT PROG_PK PRIMARY KEY,
LASTNAME VARCHAR2(30),
FIRSTNAME VARCHAR2(30),
HIREDATE DATE ,
PROJ_ID VARCHAR2(5),
LANGUAGE VARCHAR2(15),
TASKNO NUMERIC(2),
PRIVILEGE VARCHAR2(25)
)
INSERT INTO PROGRAMMER VALUES (201,'Gupta','Saurav',to_date('1/1/95','mm/dd/yy')
,'NPR','VB',52,'SECRET')
INSERT INTO PROGRAMMER VALUES (390,'Ghosh','Pinky',TO_DATE('1/5/93','MM/DD/YY'),
'KCW','java',11,'TOP SECRET')
INSERT INTO PROGRAMMER VALUES (789,'Agarwal','Praveen',TO_DATE('8/31/98','MM/DD/
YY'),'rnc','VB',11,NULL)
INSERT INTO PROGRAMMER VALUES (134,'Chaudhary','Supriyo',TO_DATE('7/15/95','MM/D
D/YY'),'TIPPS','c++',52,'SECRET')
INSERT INTO PROGRAMMER VALUES (896,'Jha','Ranjit',TO_DATE('06/15/99','MM/DD/YY')
,'KCW','JAVA',10,'TOP SECRET')
INSERT INTO PROGRAMMER VALUES (345,'John','Peter',TO_DATE('11/15/99','MM/DD/YY')
,'TIPPS','java',52,NULL)
INSERT INTO PROGRAMMER VALUES (563,'Anderson','Andy',TO_DATE('8/15/94,'MM/DD/YY'
)','NITTS','c++',89,'CONFIDENTIAL')
SELECT EMP_NO,LASTNAME,FIRSTNAME,TO_DATE(HIREDATE,'MM/DD/YY'),PROJ_ID,LANGUAGE,T
ASKNO,PRIVILEGE FROM PROGRAMMER
select * from programmer
-----------------------------------WEATHER---------------------------------------------------------------CREATE TABLE WEATHER
(CITY VARCHAR2(15),
STATE VARCHAR2(30),
HIGH NUMBER,
LOW NUMBER
)
INSERT INTO WEATHER VALUES ('CALCUTTA','WEST BENGAL',105,90)
INSERT INTO WEATHER VALUES ('TRIVENDRUM','KERALA',101,92)
INSERT INTO WEATHER VALUES ('MUMBAI','MAHARASHTRA',88,69)
INSERT INTO WEATHER VALUES ('BANGALORE','KARNATAKA',77,60)
INSERT INTO WEATHER VALUES ('NEW DELHI',NULL,80,72)
SELECT * FROM WEATHER
-------------------------------------------------------------------------------------------------------------BOOKS---------------------CREATE TABLE BOOK
(BOOKID NUMBER,
TITLE VARCHAR(5),
TOPICID VARCHAR2(6),

PUBLISHER_NAME VARCHAR2(25),
PLACE_OF_PUBLICATION VARCHAR2(10),
PRICE NUMBER ,
PUERCHASE_DATE DATE,
SHELFNO VARCHAR2(3)
)
INSERT INTO BOOK VALUES(8293,'DBMS','DB1','PRENTICE HALL','MUMBAI',225,TO_DATE('
1/1/95','MM/DD/YY'),'S11')
INSERT INTO BOOK VALUES(5645,'DBMS','DB1','PEARSON EDUCATION','MUMBAI',655,TO_DA
TE('1/05/93','MM/DD/YY'),'S12')
INSERT INTO BOOK VALUES(6565,'C','C1','TMH','MUMBAI',840,TO_DATE('8/31/98','MM/D
D/YY'),'S66')
INSERT INTO BOOK VALUES(6567,'C++','CPLUS1','ABC PUBLISHERS','DELHI',330,TO_DATE
('7/15/95','MM/DD/YY'),'S77')
INSERT INTO BOOK VALUES(4576,'JAVA','JAVA1','GURU GOBIND PUBLICATIONS','DELHI',5
00,TO_DATE('6/15/97','MM/DD/YY'),'S87')
INSERT INTO BOOK VALUES(3433,'OOPS','OOPS1','DAVE PUBLISHERS','PUNE',600,TO_DATE
('11/15/99','MM/DD/YY'),'S56')
INSERT INTO BOOK VALUES(4655,'SAD','SAD1','SAJAN PUBLICATIONS','COCHIN',700,TO_D
ATE('8/15/94','MM/DD/YY'),'S76')
SELECT * FROM BOOK
---------------QUERIES----------------UPDATE PROGRAMMER SET PROJ_ID='NITTS',LANGUAGE='C++'
WHERE FIRSTNAME='Saurav' AND LASTNAME='GUPTA'
SELECT * FROM PROGRAMMER
----------------------------UPDATE BOOK SET SHELFNO='S10'
WHERE TITLE='DBMS'
SELECT * FROM BOOK
--------------------------DELETE FROM PROGRAMMER
WHERE FIRSTNAME='SUPRIYO' AND LASTNAME='CHAUDHRY'
----------------------------------------ALTER TABLE WEATHER ADD CLIMATE VARCHAR2(40) CONSTRAINT CK2 CHECK (CLIMATE IN('R
AINY','CLOUDY','SUNNY','SNOW'))
----------------------DELETE FROM WEATHER
SELECT * FROM WEATHER
------------------------------------

CREATE TABLE SUPPLIER


(
SUPPLIERID NUMBER(30) PRIMARY KEY,
SNAME VARCHAR(30),
SCITY VARCHAR2(30),
SPHONE NUMBER(10) NOT NULL,
EMAIL VARCHAR2(50) UNIQUE
)
INSERT INTO SUPPLIER VALUES(1,'DILIP','CHENNAI',89999000,'[email protected]');
INSERT INTO SUPPLIER VALUES(2,'Tarun','Madurai',8999911111,'[email protected]')
INSERT INTO SUPPLIER VALUES(3,'Naresh','Coimbatore',8999922222,'[email protected]
m')
INSERT INTO SUPPLIER VALUES(4,'Ganesan','Trichy',8999933333,'[email protected]'
)

create table CUSTOMER


(
CUSTID INT PRIMARY KEY,
FNAME VARCHAR(30),
LNAME VARCHAR(30),
ADDRESS VARCHAR(50),
PHONENO INT NOT NULL,
CITY VARCHAR(20),
COUNTRY VARCHAR(20),
DATEFIRSTPURCHASED DATE,
SUPPLIERID INT REFERENCES SUPPLIER(SUPPLIERID)
)
INSERT INTO CUSTOMER VALUES(1001,'Das','Jeyaseelan','119 park Avenue II street',
'9841093428','Coimbatore','India',TO_DATE('10-jan-2004','DD-MON-YYYY'),1)
INSERT INTO CUSTOMER VALUES(2001,'Gopi','Govindraj','241, I floor,Kamaraj street
, Madippakkam',9444124590,'Chennai','India',TO_DATE('25-mar-2005','DD-MON-YYYY')
,4)
INSERT INTO CUSTOMER VALUES(1201,'Dilip','Kishore','43, II Avenue, Anna Nagar',
9997234534,'Bangalore','India',TO_DATE('20-aug-2004','DD-MON-YYYY'),2)
INSERT INTO CUSTOMER VALUES(1300,'Aanand','Chowdhury','42/1 sector 1, II Street'
,9841054348,'Bangalore','India',TO_DATE('15-may-2005','DD-MON-YYYY'),2)
INSERT INTO CUSTOMER VALUES(1220,'Chandra','Nagarajan','83, lal bagh',9841067235
6,'Bangalore','India',TO_DATE('12-FEB-2006','DD-MON-YYYY'),4)
INSERT INTO CUSTOMER VALUES(1221,'Abhishek','Kumar','13,kishori park',9444762390
1,'Chennai','India',TO_DATE('15-may-2004','DD-MON-YYYY'),1)

INSERT INTO CUSTOMER VALUES(1320,'Nikhil','Pandit','218, alwaanya street',944489


23091,'Salem','India',TO_DATE('21-apr-2006','DD-MON-YYYY'),3)
INSERT INTO CUSTOMER VALUES(1222,'Meenu','Monica','C11, church road',98410563421
,'Trichy','India',TO_DATE('30-aug-2004','DD-MON-YYYY'),1)
INSERT INTO CUSTOMER VALUES(1225,'Pavan','Kumar','128/A, North Mada Street',9993
4782103,'maduari','India',TO_DATE('18-aug-2004','DD-MON-YYYY'),4)

CREATE TABLE ITEMS


(
ITEMID NUMERIC(5) PRIMARY KEY,
ITEMNAME VARCHAR(35),
SUPPLIERID NUMERIC(5),
MINQTY NUMERIC(5) NOT NULL,
MAXQTY NUMERIC(5) NOT NULL,
PRICE NUMERIC(5)
);
INSERT
INSERT
INSERT
INSERT
INSERT
INSERT
INSERT
INSERT
INSERT

INTO
INTO
INTO
INTO
INTO
INTO
INTO
INTO
INTO

ITEMS
ITEMS
ITEMS
ITEMS
ITEMS
ITEMS
ITEMS
ITEMS
ITEMS

VALUES(20,'PEERS SOAP',4,7,20,30.00)
VALUES(21,'V.V.D COCONUT OIL 200ML',2,8,15,79)
VALUES(22,'PONDS POWDER',3,6,25,106.00)
VALUES(23,'REYNOLDS PEN-BLUE',1,10,30,15.00)
VALUES(24,'REYNOLDS PEN-BLACK',1,10,30,16.00)
VALUES(25,'MAYSORE SANDLE SOAP',4,7,25,25.00)
VALUES(26,'FAIR AND LOVELY CREAM 50G',3,5,15,55.00)
VALUES(27,'REXONA DEO SPRAY',2,5,20,100.00)
VALUES(28,'DOVE SOAP',4,7,15,85.00)

CREATE TABLE ORDERS


(ORDERID NUMBER PRIMARY KEY ,
ORDERDATE DATE,
CUSTID NUMBER,
QUANTITY NUMBER CONSTRAINT CHK5 CHECK(QUANTITY >0),
ITEMID INT REFERENCES ITEMS(ITEMID)
)

INSERT
INSERT
INSERT
INSERT

INTO
INTO
INTO
INTO

ORDERS
ORDERS
ORDERS
ORDERS

VALUES(1,TO_DATE('12-JAN-2004','DD-MON-YYYY'),1001,30,25)
VALUES(2,TO_DATE('6-MAY-2005','DD-MON-YYYY'),1202,38,24)
VALUES(3,TO_DATE('16-DEC-2006','DD-MON-YYYY'),1220,10,22)
VALUES(4,TO_DATE('21-MAY-2004','DD-MON-YYYY'),1233,12,21)

----------------------QUERIES ----------------------------------------CUSTOMER,ORDER,SUPPLIER,ITEM--------------------(1)-----Display the maximum price of the items ordered.


------select i.name,i.price
from items i
where price in(select max(price)
from orders o, items i
where o.itemid=i.itemid);
--------

(2)----For all of the items that were ordered in the ORDERS table, what is the p
rice of the lowest item ordered?
------select i.name,price
from items
where price in (select min(name)
from items i,orders1 o
where i.itemid=o.itemid);
------(3)----How many people are in each unique state in the customer table? Select th
e state and display the number of
people in each.
----select distinct(count(custid))TOTAL,city from customer group by city;
(4)---How many people are in each unique state in the customers table that have
more than one person in the state?
Select the state and display the number of how many people are in each if it's g
reater than 1.
----------select
-----------(5)----From the ORDERS table, select the item, maximum price, and minimum price
for each
specific item in the table. Only display the results if the maximum price for on
e of the items
is greater than 190.00.
------select i.itemS,i.max(price),i.min(price)
from itemS i,orders1 o
where i.itemid=o.itemid &&
exists(select price
from items
having max(price)>190.00);
(6)---How many orders did each customer make? Use the ORDERS table. Select the c
ustid,
number of orders they made, and the sum of their orders if they purchased more t
han 1
item.
--------select o.count(orderid) No_Of_Order,c.custid,c.count(cusTid) No_OF_CUsTOMER
from orders1 o,customer c
where o.custid=c.custid;
ORDERS AND CUSTOMERS:
select * from customer;
==Select the fname, city and country from the customers table for all of the row
s where the city value is either: Chennai, Salem or Madurai.
select fname,lname,country from customer where city in('chennai','salem','maduar
ai');
---------------------------------------------------------------------------------------==Write a query using a join to determine which items were ordered by each of th
e customers in the customer table.
Select the custid, fname, lname, datefirstpurchased, item and price for everythi
ng each customer purchased in the item table.

select * from customer join orders1 on customer.custid=orders1.custid;


--------------------------------------------------------------------------------------==Display using a subquery all the orders for dove soap .
select o.orderid from orders1 o,items i where i.itemid=(select itemid from items
where name='dove soap');
--------------------------------------------------------------------------------------==Display the order details supplied by different suppliers.
select o.orderid from orders1 o,customer c where o.custid=c.custid;
--------------------------------------------------------------------------------------==Display the item names for all the orders.( use a non equi join)
select name from items where itemid in (select itemid from orders1 where items.i
temid=orders1.itemid);
--------------------------------------------------------------------------------------------

-------WORLD CITY------------------------------------------------------create table worldcity(city varchar(20),


country varchar(20),
continent varchar(20),
latitude number,
northsouth varchar(20),
longitude number,
eastwest varchar(20));
insert into worldcity values('madrid','spain','eur',40,'n',3,'w');
alter table worldcity add primary key(city);
select city,country from worldcity where city like 'r%';
select city,country from worldcity where city like '%a';
select city,country from worldcity where city like '_a%';
select city,country from worldcity where city like 'm_____';
select * from worldcity;

You might also like