0% found this document useful (0 votes)
36 views

Assignments - Lab

The document provides details about lab assignments to create tables, insert data, and write queries. It includes the structure and sample data for tables like client_master, product_master, sales_master, sales_order, and sales_order_details. Students are asked to perform operations like creating tables, inserting data, and answering queries on the tables.

Uploaded by

Adarsh Mishra
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views

Assignments - Lab

The document provides details about lab assignments to create tables, insert data, and write queries. It includes the structure and sample data for tables like client_master, product_master, sales_master, sales_order, and sales_order_details. Students are asked to perform operations like creating tables, inserting data, and answering queries on the tables.

Uploaded by

Adarsh Mishra
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

DEPARTMENT OF COMPUTER SCIENCE

Lab Assignment -1
Create following tables using DDL commands:
i) Table name : client_master
columnname datatype size
client_no Varchar 6
name Varchar 20
address1 Varchar 30
address2 Varchar 30
city Varchar 15
state Varchar 15
pincode Int 6
bal_due Float 10,2
ii) Product_master
Columnname Datatype Size

Product_no Varchar 6
Description Varchar 20
Profit_percent Int 6
Unit_measure Varchar 10
Qty_on_hand Int 6
Reorder_lvl Int 6
Sell_price Float 7,2
Cost_price Float 7,2
DEPARTMENT OF COMPUTER SCIENCE

Lab Assignment – 2

Insert the following data into the tables using DML commands

Clientno Name City Pincode state bal.due

0001 Ivan Bombay 400054 Maharashtra 15000


0002 Vandan Madras 780001 Tamilnadu 0
0003 Pramad Bombay 400057 Maharashtra 5000
0004 Basu Bombay 400056 Maharashtra 0
0005 Ravi Delhi 100001 2000
0006 Rukmin Bombay 400050 Maharashtra 0
i

ProductNo Desciption Profit Unit Quantity Reorder Sell Cost


% measure on hand level Price price

P00001 1.44floppies 5 Piece 100 20 525 500


P03453 Monitors 6 piece 10 3 1200 11200
P06734 Mouse 5 piece 20 5 1050 500
P07865 1.22floppies 5 piece 100 20 525 500
P07868 Keyboards 2 piece 10 3 3150 3050
P07885 CDDrive 2.5 piece 10 3 5250 5100
P07965 540 HDD 4 piece 10 3 8400 8000
P07975 1.44Drive 5 piece 10 3 1050 1000
P08865 1.22Drive 5 piece 2 3 1050 1000
DEPARTMENT OF COMPUTER SCIENCE

Lab Assignment – 3

On the basis of above two tables answer the following Questions:


i. Find out the names of all the clients.
ii. Retrieve the list of names and cities of all the clients.
iii. List the various products available from the product_master table.
iv. List all the clients who are located in Bombay.
v. Display the information for client no 0001 and 0002.
vi. Find the products with description as ‘1.44 Drive’ and ‘1.22 Drive’.
vii. Find all the products whose sell price is greater then 5000.
viii. Find the list of all clients who stay in city ‘Bombay’ or city ‘Delhi’ or
‘Madras’.
ix. Find the product whose selling price is greater than 2000 and less than or equal
to 5000.
x. List the name, city and state of clients not in the state of ‘Maharashtra’.
xi. Change the selling price of ‘1.44 floppy drive’ to Rs.1150.00
xii. Delete the record with client 0001 from the client_master table.
xiii. Change the city of client_no ’0005’ to Bombay.
xiv. Change the bal_due of client_no 0001 to 1000.
xv. Find the products whose selling price is more than 1500 and also find the new
selling price as original selling price*15.
xvi. Find out the clients who stay in a city whose second letter is a.
xvii. Find out the name of all clients having ‘a’ as the second letter in their names.
xviii. List the products in sorted order of their description.
xix. Count the total number of orders.
xx. Calculate the average price of all the products.
xxi. Calculate the minimum price of products.
xxii. Determine the maximum and minimum prices. Rename the tittle as ‘max_price’
and min_price respectively.
xxiii. Count the number of products having price greater than or equal to 1500.
DEPARTMENT OF COMPUTER SCIENCE

Lab Assignment – 4

Create the following tables:


i. Sales_master
Columnname Datatype Size Attributes

Salesman_no varchar2 6 Primary key/first letter Must


start with ‘s’
Sal_name varchar2 20 Not null
Address varchar2 Not null
City varchar2 20
State varchar2 20
Pincode Number 6
Sal_amt Number 8,2 Not null,can not be 0
Tgt_to_get Number 6,2 Not null, can not be 0
Ytd_sales Number 6,2 Not null,can not be 0
Remarks Varchar2 30

ii. Sales_order
Columnname Datatype Size Attributes
S_order_no varchar2 6 Primary/first letter must be 0
S_order_date Date 6 Primary key reference client
no of client_master table
Client_no Varchar2 25
Dely_add Varchar2 6
Salesman_no Varchar2 6 Foreign key references
salesman_no of
salesman_master table
Dely_type Char 1 Delivery part(p)/full(f), default f
Billed_yn Char 1
Dely_date Date Can not be less
than s_order_date
Order_status Varchar2 10 Values (‘inprocess’;
’fulfilled’; backorder’;
’canceled’
DEPARTMENT OF COMPUTER SCIENCE
iii. Sales_order_details

Column Datatype Size Attributes

S_order_no Varchar2 6 Primarykey/foreignkey references


order_no of sales_order
Product_no Varchar2 6 Primarykey/foreignkey references
product_no of product_master
Qty_order Number 8
Qty_disp Number 8
Product_rate Number 10,2

1. Insert the following data into their respective tables using insert statement:
Data for sales_man master table
Salesm Sales Address City Pi State Salamt Tgt_to_ Ytd Remark
an_ no man nc get Sales
name od
500001 Kiran A/14 worli Bombay 400002 Mah 3000 100 50 Good

500002 Manish 65,nariman Bombay 400001 Mah 3000 200 100 Good

500003 Ravi P-7 Bandra Bombay 400032 Mah 3000 200 100 Good

500004 Ashish A/5 Juhu Bombay 400044 Mah 3500 200 150 Good

Data for sales order table:


S_orderno S_orderdate Clientno Delyty Bill Salesmanno Delaydat Orderstatus
pe yn e

019001 12-jan-96 0001 F N 50001 20-jan-96 Ip

019002 25-jan-96 0002 P N 50002 27-jan-96 C

016865 18-feb-96 0003 F Y 500003 20-feb-96 F

019003 03-apr-96 0001 F Y 500001 07-apr-96 F

046866 20-may-96 0004 P N 500002 22-may-96 C

010008 24-may-96 0005 F N 500004 26-may-96 Ip


DEPARTMENT OF COMPUTER SCIENCE

(iii) Data for sales_order_details table:

S_order no Productno Qtyordered Qtydisp Product_rate


019001 P00001 4 4 525
019001 P07965 2 1 8400
019001 P07885 2 1 5250
019002 P00001 10 0 525
046865 P07868 3 3 3150
046865 P07885 10 10 5250
019003 P00001 4 4 1050
019003 P03453 2 2 1050
046866 P06734 1 1 12000
046866 P07965 1 0 8400
010008 P07975 1 0 1050
010008 P00001 10 5 525

Answer the following Queries


i. Make the primary key to client_no in client_master.
ii. Add a new column phone_no in the client_master table.
iii. Add the not null constraint in the product_master table with the columns description,
profit percent, sell price and cost price.
iv. Change the size of client_no field in the client_master table.
v. Select product_no, description where profit percent is between 20 and 30 both
inclusive.
DEPARTMENT OF COMPUTER SCIENCE

Lab Assignment – 5

1. Demonstrate the use of all number functions of SQL.


2. Use decode/case to solve the following queries
Snam Divisio
Sname Division e n
A 1 A 1
B 2 B 2
C 3 C 3
D 0 D 0

3. Use decode/case to solve the following queries

Sname Result
Sname Marks
Raj First
Raj 65
Amit Fail
Amit 32
Sanjay Second
Sanjay 45
Rohit Third
Rohit 40
Anil Third
Anil 35
DEPARTMENT OF COMPUTER SCIENCE
Lab Assignment -6

1. Demonstrate the use of all string functions available in SQL.


2. Solve the following queries:

Empc Empname Empcod Empname


ode e

E1 001Rajku E1 Rajkumar
mar E2 Ramkumar
E2 Ramkumar E4 Ravikumar
002 3. Solve the
following queries:
E4 Ravikumar
003

4. Solve the following queries:


DEPARTMENT OF COMPUTER SCIENCE

Lab Assignment – 7

1. Demonstrate all date function supported by SQL.


2. We have one table emp containing ename, dob, doj. Print “Happy Birthday” on their
birthdays.
3. Calculate and print the current age of the employees.
4. Write a query for displaying the list of employees who are retiring today.

Lab Assignment – 8

1. Create Table ITEM with attributes (ItemNo., ItemName,Qty, UnitPrice, Pdate) and
populate with suitable data and Write queries for
i. List minimum UnitPrice. From item table
ii. List maximum UnitPrice. From item table
iii. List the total number of items in the item table.

2. Create table Bill with attributes (BillNo, Billdate, amount) and populate the table with
suitable data and Write SQL query to
i. List out the number of unique dates on which bill has been generated.
ii. List out the unique dates on which bill has been generated.
DEPARTMENT OF COMPUTER SCIENCE

Lab Assignment – 9

1. Write a query to find out the second highest salary of the employee from employee
table.
2. Write a query to find out the nth highest salary of the employee from employee table.
3. Write a query to delete duplicate rows from employee table.
4. Create a table using the existing table.
5. Write a query to find out the second lowest salary of the employee from employee
table.
6. Write a query to find out the nth lowest salary of the employee from employee table.

Lab Assignment – 10

1. Write a query to demonstrate the use of join.


2. Write a query to demonstrate the use of left join.
3. Write a query to demonstrate the use of right join.
4. Write a query to demonstrate the use of full join.
5. Write a query to demonstrate the use of self join.
DEPARTMENT OF COMPUTER SCIENCE

Lab Assignment - 11

1. Create an index on the table client_master, field client_no.


2. Create an index on the sales_order, field s_order_no.
3. Create an composite index on the sales_order_details table for the columns
s_order_no and product_no.
4. Create an uniQuestionindex on the table salesman_master, field salesman_no.
5. Create view on salesman_master whose sal_amt is less than3500.
6. Createa view client_view on client_master and rename the columns as name,
add1, add2, city, pcode, state respectively.
7. Select the client names from client_view who lives in city ‘Bombay’
8. Drop the view client_view.

You might also like