0% found this document useful (0 votes)
33 views27 pages

Assignment

Uploaded by

Ankur Garg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views27 pages

Assignment

Uploaded by

Ankur Garg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 27

RAJ KUMAR GOEL INSTITUTE OF

TECHNOLOGY ,GHAZIABAD

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING


(AI&ML)
NAME : Nimisha Kulshrestha ROLL NO. : 2100331550055
FACULTY : Department : CSE(IOT)
Course Name : DBMS Lab Manual Course Code : KCS-551
Year/Sem : 3rd / 5th Academic Year : 2023-24
Email ID : [email protected]
INDEX

Experi Experiment Date of Date of Faculty


ment Conduction Submission Signature
Name
No.
1 Creating tables and writing sql
queries.
2 To implement various DML
operations on table.

3 To implement the
restrictions/constraints on table.

4 To alter the structure of the table.

5 To implement the concept of joins.

6 Entity -Relationship diagram.

7 To implement the concept of


grouping of data , grouping
data from tables.
8 To implement the concept of
subqueries.

Assignment No.1

Q1. Create the following tables:

i) client_master
columnname datatype size client_no
varchar2 6 name varchar2 20
address1 varchar2 30 address2
varchar2 30 city varchar2 15 state
varchar2 15 pincode number 6
bal_due number 10,2

ii) Product_master

Columnname datatype size


Product_no varchar2 Description
Profit_percent varchar2
Unit_measure varchar2 Qty_on_hand
number
Reoder_lvl number
Sell_price number
Cost_price number
Q2- Insert the following data into their respective tables:

Clientno Name city pincode state bal.due


0001 Ivan Bombay 400054 Maharashtra 15000
0002 Vandana Madras 780001 Tamilnadu 0
0003 Pramada Bombay 400057 Maharashtra 5000
0004 Basu Bombay 400056 Maharashtra 0
0005 Ravi Delhi 100001 2000

0006 Rukmini Bombay 400050 Maharashtra 0

Data for Product Master:


Product No. Desciption Profit % Unit Qty Reorder Sell Cost
Percent measured on hand lvl price price

P00001 1.44floppies 5 piece 100 20 525 500


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

Q3:- On the basis of above two tables answer the following Queries:
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 than 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’.

OUTPUT
1 i)

ii)

2 i)

ii)

3 i)

ii)
iii)

iv)

v)

vi)

vii)

viii)
ix)

x)

Assignment No.2

Question.1 Using the table client master and product master answer the following Queries.

i. Change the selling price of ‘1.44 floppy drive to Rs.1150.00 ii.


Delete the record with client 0001 from the client master table.
iii. Change the city of client_no’0005’ to Bombay. iv.
Change the bal_due of client_no ‘0001, to 1000.
v. Find the products whose selling price is more than 1500 and also find the new selling price as
original selling price *15.
vi. Find out the clients who stay in a city whose second letter is a.
vii. Find out the name of all clients having ‘a’ as the second letter in their names.
viii. List the products in sorted order of their description.
ix. Count the total number of orders
x. Calculate the average price of all the products.
xi. Calculate the minimum price of products.
xii. Determine the maximum and minimum prices . Rename the tittle as ‘max_price’ and min_price
respectively.
xiii. Count the number of products having price greater than or equal to 1500.

OUTPUT:
i)
ii)

iii)

iv)

v)

vi)

Vii)
viii)

ix)

x)

xi)

xii)
xiii)

Assignment No.3

Syntax :
Create table table name
(columnname datatype (size) references another table name);

Foreign key as a table constraint:

Syntax :
Create table name (columnname datatype
(size)…. primary key
(columnname);
foreign key (columnname)references table name);

Check Integrity Constraints: Use the check constraints when you need to enforce intergrity
rules that can be evaluated based on a logical expression following are a few examples of
appropriate check constraints.
● A check constraints name column of the coient_master so that the name is entered in upper case.
● A check constraint on the client_no column of the client _master so that no client_no value starts
with ‘c’

Syntax:
Create table tablename
(columnname datatype (size) CONSTRAINT
constraintname) Check (expression));

Question.2 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, cannot be 0
Tgt_to_get Number 6,2 Not null, cannot be 0
Ytd_sales Number 6,2 Not null, cannot 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 clientno 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 lessthan s_order_date
Order_status Varchar2 10 Values (‘in
process’;’fulfilled’;back
order’;’canceled

I. Sales_order_details
Column Datatype Size Attributes

S_order_no Varchar2 6 Primary key/foreign key


references s_order_no of
sales_order
Product_no Varchar2 6 Primary key/foreign key
references product_no
of product_master
Qty_order Number 8
Qty_disp Number 8
Product_rate Number 10,2

Insert the following data into their respective tables using insert statement:

Data for sales_man master table


Salesman_no Salesman Address City Pin code State Salamt Tgt_ Ytd Remark
name to_g Sales
et
500001 Kiran A/14 worli Bomba 400002 Mah 3000 100 50 Good
y
500002 Manish 65,nariman Bomba 400001 Mah 3000 200 100 Good
y
500003 Ravi P-7 Bandra Bomba 400032 Mah 3000 200 100 Good
y
500004 Ashish A/5 Juhu Bomba 400044 Mah 3500 200 150 Good
y
Data for salesorder table:

S_orderno S_orderdate Client no Dely Bill yn Salesman no Delay Orderstatus


type date
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- C
96
010008 24-may-96 0005 F N 500004 26-may- Ip
96

(i)
Data for sales_order_details table:

S_order no Product no Qty ordered Qty disp 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

OUTPUT:
Creation i)

ii)

iii)

Insertion i)
ii) iii)

Assignment No.4
Question 1. Create the following tables: Challan_Header
Column name data type size Attributes Challan_no
varchar2 6 Primary key
s_order_no varchar2 6 Foreign key references s_order_no of
sales_order table
challan_date date not null
billed_yn char

Table Name : Challan_Details 1 values (‘Y’,’N’). Default ‘N’


Column name data type size Attributes
Challan_no varchar2 6 Primary key/Foreign key references
Product_no of product_master
Qty_disp number 4,2 not null

Q2. Insert the following values into the challan header and challan_details tables:

(i) Challan No S_order No Challan Date Billed


CH9001 019001 12-DEC-95 Y
CH865 046865 12-NOV-95 Y
CH3965 010008 12-OCT-95 Y
Data for challan_details table
Challan No Product No Qty Disp
CH9001 P00001 4
CH9001 P07965 1
CH9001 P07885 1
CH6865 P07868 3
CH6865 P03453 4
CH6865 P00001 10
CH3965 P00001 5
CH3965 P07975 2

Objective – Answer the following Queries

Q1. Make the primary key to client_no in client_master.


Q2. Add a new column phone_no in the client_master table.
Q3. Add the not null constraint in the product_master table with the columns description, profit percent ,
sell price and cost price.
Q4. Change the size of client_no field in the client_master table.
Q5. Select product_no, description where profit percent is between 20 and 30 both inclusive.

OUTPUT

1
i)
ii)

2
i)

ii)

3
i)

ii)
iii)
iv)
v)

Assignment No.5
A. Consider the following schema for a Library Database:

BOOK (Book_id, Title, Publisher_Name, Pub_Year)

BOOK_AUTHORS (Book_id, Author_Name)

PUBLISHER (Name, Address, Phone) BOOK_COPIES

(Book_id, Branch_id, No-of_Copies)

BOOK_LENDING (Book_id, Branch_id, Card_No, Date_Out, Due_Date)

LIBRARY_BRANCH (Branch_id, Branch_Name, Address)

Write SQL queries to :

1. Retrieve details of all books in the library – id, title, name of publisher, authors, number of copies in
each branch, etc.

2. Get the particulars of borrowers who have borrowed more than 3 books, but from Jan 2017 to Jun
2017.
3. Delete a book in BOOK table. Update the contents of other tables to reflect this data manipulation
operation.

4. 4. Partition the BOOK table based on year of publication. Demonstrate its working with a simple
query.

5. Create a view of all books and its number of copies that are currently available in the Library.

OUTPUT

1 i)
ii)

iii)

iv)

v)

Assignment NO. 6
Answer the following Queries:
QUERIES -

1. Find out the product which has been sold to ‘Ivan Sayross.’ 2. Find
out the product and their quantities that will have do delivered.
3. Find the product_no and description of moving products.
4. Find out the names of clients who have purchased ‘CD DRIVE’
5. List the product_no and s_order_no of customers haaving qty ordered less than 5 from the order
details table for the product “1.44 floppies”.
6. Find the products and their quantities for the orders placed by ‘Vandan Saitwal ’ and “Ivan
Bayross”.
7. Find the products and their quantities for the orders placed by client_no “ C00001” and
“C00002”
8. Find the order No,, Client No and salesman No. where a client has been received by more than
one salesman.
9. Display the s_order_date in the format “dd-mm-yy” e.g. “12- feb-96”
10. Find the date , 15 days after date.

OUTPUT
Assignment No.7

Objective- Answer the following Queries:

Q1.- Print the description and total quantity sold for each product.

Q2.- Find the value of each product sold.

Q3.- Calculate the average quantity sold for each client that has a maximum order value of 15000.

Q4.- Find out the products which has been sold to Ivan.

Q5.- Find the names of clients who have ‘CD Drive’.

Q6.- Find the products and their quantities for the orders placed by ‘Vandana’ and ‘Ivan’.

Q7.- Select product_no, total qty_ordered for each product.

Q8.- Select product_no, product description and qty ordered for each product.

Q9.- Display the order number and day on which clients placed their order.

Q10.- Display the month and Date when the order must be delivered.
OUTPUT
Assignment NO.8
Objective: Answer the following Queries:

QUERIES:

1. Find the product_no and description of non- moving products.


2. Find the customer name, address, city and pincode for the client who has placed order no
“019001”
3. Find the client names who have placed order before the month of may 96.
4. Find out if product “1.44 Drive” is ordered by only client and print the client_no name to whom
it was sold.
5. find the names of client who have placed orders worth Rs.10000 or more.
6. Select the orders placed by ‘Rahul Desai”
7. Select the names of persons who are in Mr. Pradeep’s department and who have also worked on
an inventory control system.
8. Select all the clients and the salesman in the city of Bombay.
9. Select salesman name in “Bombay” who has atleast one client located at “Bombay”
10. Select the product_no, description, qty_on-hand,cost_price of non_moving items in the
product_master table

OUTPUT

You might also like