You are on page 1of 12

ASSESSMENT 5

ITA1005 – DATABASE MANAGEMENT


SYSTEMS LAB
NAME: Sai kumar.p
REG.NO:18BCA0079

1. TABLE CREATION CLIENT_MASTER

SQL> CREATE TABLE CLIENT_MASTER(


CLIENT_NO VARCHAR(6) CONSTRAINT PK_CM PRIMARY KEY,
NAME VARCHAR(20),
ADDRESS1 VARCHAR(30),
ADDRESS2 VARCHAR(30),
CITY VARCHAR(15),
STATE VARCHAR(15),
PINCODE NUMBER(6),
BALANCEDUE NUMBER(10,2)); 2 3 4 5 6 7 8 9

Table created.
2. TABLE CREATION PRODUCT_MASTER

SQL> CREATE TABLE PRODUCT_MASTER(


PRODUCT_NO VARCHAR(6) CONSTRAINT PK_PM PRIMARY KEY,
DESCRIPTION VARCHAR(20),
PROFIT_PERCENT NUMBER(10),
UNIT_MEASURE VARCHAR(20),
QTY_HAND NUMBER(15),
REORDER_NO NUMBER(15),
SELL_PRICE NUMBER(10),
COST_PRICE NUMBER(10));
2 3 4 5 6 7 8 9
Table created.

3. TABLE CREATON SALE_ORDER_DETAILS.


SQL> CREATE TABLE SALE_ORDER_DETAILS(
ORDER_NO VARCHAR(6) CONSTRAINT PK_3 PRIMARY KEY,
CNAME VARCHAR(20) UNIQUE NOT NULL,
PRODUCT_NO VARCHAR(6) ,
QTY_ORDER NUMBER(8),
QTY_DISP NUMBER(8),
PRODUCT_RATE NUMBER(10,2),
CLIENT_NO NUMBER(10)); 2 3 4 5 6

Table created.

4. TABLE CREATION SALE_ORDER

SQL> CREATE TABLE SALE_ORDER(


ORDERNO VARCHAR(6),
DELY_DATE DATE
ORDER_DATE DATE ); 2

Table created.
5. ALTER COMMANDS FOR CONSTRAINS:

SQL> ALTER TABLE ORDERNO ADD PRIMARY KEY (ORDERNO);

Table altered.

SQL>
ALTER TABLE SALE_ORDER ADD FOREIGN KEY (ORDERNO) REFERENCES
ORDERNO(ORDERNO);

Table altered.

ALTER TABLE SALE_ORDER ADD FOREIGN KEY (PRODUCTNO) REFERENCES


PRODUCT_MASTER(PRODUCTNO);

Table altered.

ALTER TABLE SALE_ORDER ADD FOREIGN KEY (CNAME) REFERENCES CLIENT_MASTER(NAME);

6. SOME INSERTION COMMANDS.


1. INSERT INTO PRODUCT_MASTER VALUES('P00001','FLOPPIES',5,'PIECE',100,20,525,500);

2. INSERT INTO CLIENT_MASTER VALUES('P06734',;abiram',5,'PIECE',20,5,1050,500);

3. INSERT INTO PRODUCT_MASTER


VALUES('P03453','MONITORS',6,'PIECE',10,3,12000,11200);

4. INSERT INTO CLIENT_MASTER


VALUES('0006','RUKMINI','','','BOMBAY','MAHARASHTRA',40005,0);

5. INSERT INTO CLIENT_MASTER


VALUES('0002','VANDANA','','','MADRAS','TAMILNADU',780001,0);

6. INSERT INTO CLIENT_MASTER


VALUES('0001','IVAN','','','BOMBAY','MAHARASHTRA',400054,15000);
JOIN QUERIS.

1. Find out the product which has been sold to ‘ivan Sayross’.

SQL> select name,product_master.product_no,description,sales_order.order_no


from client_master,product_master,sales_order,sales_order_details where
client_master.name = 'Ivan Bayross' and client_master.client_no =
sales_order.client_no and sales_order.order_no = sales_order_details.order_no
and sales_order_details.product_no = product_master.product_no;

NAME PRODUCT_NO DESCRIPTION ORDER_


---------------- ------------------- ------------------- ------------
Ivan P00001 Floppies O19001

Ivan P07885 CD Drive O19001


Ivan P07965 540 HDD O19001

2. Find out the product and their quantities that will have to be delivered.

SQL> select sales_order_details.product_no,qty_ordered,description from


sales_order,sales_order_details,product_master where sales_order.order_no =
sales_order_details.order_no and sales_order_details.product_no =
product_master.product_no;

no rows selected
3. Find out the product_no and description of moving products.
SQL> select product_no from sales_order_details where product_rate =
(select max (product_rate) from sales_order_details );
PRODUCT_NO

--------------------
P07965

4. Find the name of the clients who have purchased CD drive.

SQL> select description,product_master.product_no,name from


product_master,client_master,sales_order,sales_order_details where description = 'CD
Drive' and product_master.product_no = sales_order_details.product_no and
sales_order_details.order_no =
sales_order.order_no and sales_order.client_no = client_master.client_no;

DESCRIPTION PRODUCT_NO NAME


--------------- ------------------ ------------
CD Drive P07885 Ivan

CD Drive P07885 Pradama

5. List the product no. , order_no of customers having qty_ordered less then 5 from
sales_order_details table for the product ‘1.44 floppies’.

SQL> select product_master.product_no,order_no from


product_master,sales_order_details where description = '1.44 Floppies' and
product_master.product_no = sales_order_details.product_no and qty_ordered
< 5;
PRODUCT_NO ORDER_
------------------- -----------
-
P00001 O19001
6. Find the product and their quantity for the orders placed by ‘Ivan Bayross’ and
‘Vandana Saitwal’.

SQL> select name,description,qty_ordered from


client_master,product_master,sales_order,sales_order_details where name
in('Ivan Bayross','Vandana Saitwal') and client_master.client_no =
sales_order.client_no and sales_order.order_no = sales_order_details.order_no
and
sales_order_details.product_no = product_master.product_no;

NAME DESCRIPTION QTY_ORDERED


------------ --------------------------------------------
Ivan Floppies 4

Ivan CD Drive 2
Ivan 540 HDD 2
Vandana Floppies 10

7. Find the product and quantities for the orders placed by client_no ‘C00001’
and ‘C00002’.

SQL> select description,qty_ordered from


product_master,sales_order_details,sales_order where
product_master.product_no = sales_order_details.product_no and
sales_order_details.order_no =
sales_order.order_no and client_no in('C00001','C00002');

DESCRIPTION QTY_ORDERED
------------------ --------------------
Floppies 4
Floppies 10
CD Drive 2
540 HDD 2
8. Find the order no.client and salesman no. where a client has been received by
more than one sales man

Select sale_order.orderno, client_master.client_no ,count(salesman_no) from


sale_order join client_master group by client_no having
count(salesman_no>1);

9. Display the s_order_date in the format “dd-mm-yy”


Select to_date(order_date,’dd-mm-yy’) from sale_order;

10. Find the date, 15 days after date.


Select order_date +15 from sale_order;

SUB QUERY

1. Find the product no and description for non-moving products.

SQL> select sales_order_details.product_no, description from


sales_order_details, product master on sales_order_details.product_no =
product_master.product_no where exists (select qty_disp from
product_master where qty_disp = 0);

PRODUCT_NO DESCRIPTION
-------------------- --------------------
P00101 1.44 Floppies
2. Find the customer name, address1,address2.city and pincode for the client
who has placed order no. ‘O19001’.
SQL> select name,address1,address2,city,pincode from client_master,sales_order
' on sales_order.client_no = client_master.client_no where exist (select order_no
from sales_order where order_no = O19001');

NAME ADDRESS1 ADDRESS2 CITY PINCODE


----------- ---------------- ------------------- --------------- ---------------
Ivan Worli Bombay 400054

3. Find the client name that has placed orders before the month of May’96.

SQL> select name,order_date from client_master,sales_order on


sales_order.client_no = client_master.client_no where exist (select order_date
from sale_order where order_date < '1-May-20');

NAME ORDER_DAT
---------------- ----------------
Vandana 12-JAN-08
Pradama Jaguste 20-MAY-08
Basu Navindgi 25-JAN-08
Ivan 18-FEB-08
Ivan 03-APR-08

4. Find out if the product ‘1.44 Drive’ has been ordered by any client and
print the client_no, name to whom it was sold.

SQL> select description, sales_order_details.order_no, client_master.client_no,


name from product_master, client_master,sales_order,sales_order_details on
product_master.product_no = sales_order_details.product_no and
sales_order_details.order_no = sales_order.order_no and sales_order.client_no =
client_master.client_no where exist (select description from product_master
where description = '1.44 Drive');
DESCRIPTION ORDER_ CLIENT NAME
-------------------- ------------- ------------ --------------------
1.44 Drive O46899 C00014 Ajay Navindgi

5. Find names of the clients who have placed orders worth Rs. 10000 or more.

SQL> select name,product_master.product_no,sell_price from


client_master,product_master,sales_order, sales_order_details on
product_master.product_no = sales_order_details.product_no and
sales_order_details.order_no = sales_order.order_no and sales_order.client_no =
client_master.client_no where exist (select sell_price from product_master where
sell_price >= 10000);

NAME PRODUCT_NO SELL_PRICE


--------------- -------------------- -----------------
-
Ivan P03453 - 13500

6. Select the orders placed by ‘Rahul Desai”

SQL> select name,product_master.product_no from


client_master,product_master,sales_order, sales_order_details on
product_master.product_no = sales_order_details.product_no and
sales_order_details.order_no = sales_order.order_no and sales_order.client_no =
client_master.client_no where exist (select name from client_master where name=
“Rahul desai”);

NAME PRODUCT_NO
---------------- --------------------
Rahul desai P02253
7. select the names of person who are in Mr .Pradeep’s department and who
have also worked on an inventory control system.

Select employee.empno, Department.departname from employee join department


on employee.empno=department.empno where exist (select depart name from
department where departname=’inventory control system’);

8. Select all clients and salesman in the city of Bombay.

select salesman.name ,client_master.city from salesman join

client_master on salesman.orderno=clientmaster.orderno where exist


(select city from salesman where city =”Bombay”);

located at “Bombay”.

select salesman.name ,client_master.city from salesman join client_master on


salesman.orderno=clientmaster.orderno where exist (select city from salesman where
city =”Bombay”);

10.Select the product_no,description.qty_on-hand,cost_price of non_moving


items in the product _master table.

SQL> select product_master.product_no , description product_master


.cost_price,qty_on_hand from sales_order_details, product master on
sales_order_details.product_no = product_master.product_no where exists
(select qty_disp from product_master where qty_disp = 0)

PRODUCT DESCRIPTION COST_PRICE QTY_ON_HAND


------------- -------------------- ----------------- ----------------------
P00101 1.44 Floppies 550 5

You might also like