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

Assignment 1

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

Assignment 1

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

Assignment 1

1) Create the following tables:


a. Table Name : Client_master
Description: Use to store information about client

Column Name Data Type Size Attributes


client_no varchar2 6 Primary key/first letter
must start with ‘C’
name varchar2 20 not null
address1 varchar2 30
address2 varchar2 30
city varchar2 15
state varchar2 15
pincode number 6
bal_due number 10,2

b. Table Name: product_master


Description: Use it store information about products.
Column Name Data Type Size Attributes
product_no varchar2 6 Primary key/first letter
must start with ‘P’
description varchar2 50 not null
profit_percent number 3,2 not null
unit_measure varchar2 10 not null
record_lvl number 8 not null
sell_price number 8,2 not null, cannot be 0
cost_price number 8,2 not null, cannot be 0

c. Table Name : salesman_master


Description: Use to store information about salesman working in the company
Column Name Data Type Size Attributes
salesman_no varchar2 6 Primary key/first letter
must start with ‘S’
salesman_name varchar2 20 not null
Address1 varchar2 30 not null
Address2 varchar2 30
city varchar2 20
pincode varchar2 6
state varchar2 20
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
Assignment 1

remarks varchar2 60
d. Table Name : sales_order
Description: Use to store information about order

Column Name Data Type Size Attributes


s_order_no varchar2 6 Primary key/first letter must start with
‘O’
s_order_date date
client_no varchar2 6 Foreign key references client_no of
client_master table
dely_addr varchar2 25
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 delivery :part (Y) / full (N), Default ‘N’
dely_date date cannot be less than s_order_date
order_status varchar2 10 values (‘in process’, ’Fulfilled’,
’BackOrder’, ’Canceled’)

e. Table Name: sales_order_details


Description: Use to store information about products ordered.

Column Name Data Type Size Attributes


s_order_no varchar2 6 Foreign key references s_order_no of
sales_order table
product_no varchar2 6 Foreign key references product_no of
product_master table
qty_ordered number 8
qty_disp number 8
product_rate number 10,2

f. Table Name: Challan_Header


Description: Use to store information about challans made for the orders.

Column Name Data Type Size Attributes


challan_no varchar2 6 Primary Key/First Two letters must start
with ‘CH’
s_order_no varchar2 6 Foreign Key references s_order_no of
sales_order table
challan_date date not null
billed_yn char 1 values(‘Y’,’N’)Default ‘N’
Assignment 1

g. Table Name: Challan_details


Description: use to store information about challan details

Column Name Data Type Size Attributes


challan_no varchar2 6 Primary Key/Foreign Key references
challan_no of challan_header table.
product_no varchar2 6 Primary Key/Foreign Key references
product_no of product_master table
qty_disp number 4,2 not null

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

1. Data for client_master table

Client No Name City Pin Code State Bal_Due


C00001 Ivan Bayross Bombay 400054 Maharashtra 15000
C00002 Vandana Saitwal Madras 780001 Tamil Nadu 0
C00003 Pramada Jaguste Bombay 400057 Maharashtra 5000
C00004 Basu Navindgi Bombay 400056 Maharashtra 0
C00005 Ravi Sreedharan Delhi 100001 Delhi 2000
C00006 Rukmini Bombay 400050 Maharashtra 0

2. Data for Product_master Table:

ProductNo Description Profit % UOM qty_on_hand Reorder lel Sell Price Cost Price
P00001 1.44 Floppies 5 Piece 100 20 525 500
P03453 Monitors 6 Piece 10 3 12000 11280
P06734 Mouse 5 Piece 20 5 1050 1000
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
Assignment 1

3. Data for Salesman_master table:

3. Data for salesman_master table:

Salesman_ Salesman_ Address1 Address2 City Pin State sal_amt Tgt_to Ytd Remarks
no name code Get sales
S00001 Kiran A/14 Worli Bombay 400002 MAH 3000 100 50 Good
S00002 Manish 65 Nariman Bombay 400001 MAH 3000 200 100 Good
S00003 Ravi P-7 Bandra Bombay 400032 MAH 3000 200 100 Good
S00004 Ashish A/5 Juhu Bombay 400044 MAH 3500 200 150 Good

4. Data for sales_order table :

S_order_no S_order_dat Client No Dely Bill Yn salesman Dely Date Order


e Type no Status
O19001 12-Jan-1996 C00001 F N S00001 20-Jan-1996 IP
O19002 25-Jan-1996 C00002 P N S00002 27-Jan-1996 C
O46865 18-Feb-1996 C00003 F Y S00003 20-Feb-1996 F
O19003 03-Apr-1996 C00001 F Y S00001 07-Apr-1996 F
O46866 20-May-1996 C00004 P N S00002 22-May-1996 C
O10008 24-May-1996 C00005 F N S00004 26-May-1996 IP

5. Data for sales_order_details table:

s_order_no product_no Qty ordered qty_Disp Product rate


O19001 P00001 4 4 525
O19001 P07965 2 1 8400
O19001 P07885 2 1 5250
O19002 P00001 10 0 525
O46865 P07868 3 3 3150
O46865 P07885 3 1 5250
O46865 P00001 10 10 525
O46865 P03453 4 4 1050
O19003 P03453 2 2 1050
O19003 P06734 1 1 12000
O46866 P07965 1 0 8400
O46866 P07975 1 0 1050
O10008 P00001 10 5 525
O10008 P07975 5 3 1050
Assignment 1

6. Data for challan_header table:

Challan No S Order No Challan Date Billed


CH9001 O19001 12-Dec-1995 Y
CH6865 O46865 12-Nov-1995 Y
CH3965 O10008 12-Oct-1995 Y

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

Hands-on Exercise

1) Add the following record into the challan_details table and check if the records gets added or
not. Note the observation for each of them

CH9001 P00001 5
P785341 P06734 9
P00001 CH9001 1
2) Drop the table product_master. Can the product_master be dropped. If not, Note the error
message.
3) Drop the table challan_details, challan_header and product_master in specified sequence.
4) What conclusions can you draw, performing the above tasks?
Assignment 1

SIXTY SELF REVIEW SQL SENTENCE CONSTRUCTS FOR PRACTICE


1. Single table retrieval
1) Find out the names of all the clients.
2) Print the entire client_master table.
3) Retrieve the list of names and the cities of all the clients
4) List the various products available from the product_master table.
5) Find the names of all clients having ‘a’ as the second letter in their table.
6) Find the names of all clients who stay in a city whose second letter is ‘a’
7) Find out the clients who stay in a city ‘Bombay’ or city ‘Delhi’ or city ‘Madras’.
8) List all the clients who are located in Bombay.
9) Print the list of clients whose bal_due are greater than value 10000
10) Print the information from sales_order table of orders placed in the month of
January.
11) Display the order information for client_no ‘C00001’ and ‘C00002’
12) Find the products with description as ‘1.44 Drive’ and ‘1.22 Drive’
13) Find the products whose selling price is greater than 2000 and less than or equal
to 5000
14) Find the products whose selling price is more than 1500 and also find the new
selling price as original selling price * 15
15) Rename the new column in the above query as new_price
16) Find the products whose cost price is less than 1500
17) List the products in sorted order of their description.
18) Calculate the square root the price of each product.
19) Divide the cost of product ‘540 HDD’ by difference between its price and 100
20) List the names, city and state of clients not in the state of Maharashtra
21) List the product_no, description, sell_price of products whose description begin
with letter ‘M’
22) List all the orders that were canceled in the month of May.
2. Set Functions and Concatenation :
23) Count the total number of orders.
24) Calculate the average price of all the products.
25) Calculate the minimum price of products.
26) Determine the maximum and minimum product prices. Rename the title as
max_price and min_price respectively.
27) Count the number of products having price greater than or equal to 1500.
28) Find all the products whose qty_on_hand is less than reorder level.
Assignment 1

29) Print the information of client_master, product_master, sales_order table in the


following formate for all the records
{cust_name} has placed order {order_no} on {s_order_date}.
3. Having and Group by:
30) Print the description and total qty sold for each product.
31) Find the value of each product sold.
32) Calculate the average qty sold for each client that has a maximum order value of
15000.00
33) Find out the total sales amount receivable for the month of jan. it will be the
sum total of all the billed orders for the month.
34) Print the information of product_master, order_detail table in the following
format for all the records
{Description} worth Rs. {Total sales for the product} was sold.
35) Print the information of product_master, order_detail table in the following
format for all the records
{Description} worth Rs. {Total sales for the product} was produced in the month
of {s_order_date} in month formate.
4. Nested Queries :
36) Find the product_no and description of non-moving products.
37) Find the customer name, address1, address2, city and pin code for the client
who has placed order no ‘O19001’
38) Find the client names who have placed orders before the month of May, 1996
39) Find out if product ‘1.44 Drive’ is ordered by client and print the client_no, name
to whom it is was sold.
40) Find the names of clients who have placed orders worth Rs. 10000 or more.
5. Queries using Date:
41) Display the order number and day o which clients placed their order.
42) Display the month (in alphabets) and date when the order must deliver.
43) Display the s_order_date in the format ‘DD-MM-YY’. E.g. 12-February-1996
44) Find the date, 15 days after today’s date.
45) Find the number of days elapsed between today’s date and the delivery date of
the orders placed by the clients.
6. Table Updations:
46) Change the s_order_date of client_no ‘C00001’ to 24/07/96.
47) Change the selling price of ‘1.44 Floppy Drive’ to Rs. 1150.00
48) Delete the records with order number ‘O19001’ from the order table.
Assignment 1

49) Delete all the records having delivery date before 10th July’96
50) Change the city of client_no ‘C00005’ to ’Bombay’.
51) Change the delivery date of order number ‘O10008” to 16/08/96
52) Change the bal_due of client_no ‘C00001’ to 1000
53) Change the cost price of ‘1.22 Floppy Drive’ to Rs. 950.00.

You might also like