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

Assignment03 DBS (Rooha)

database/sql

Uploaded by

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

Assignment03 DBS (Rooha)

database/sql

Uploaded by

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

Database Systems Lab

Lab Task:10
Semester IV
Submitted to: Sir Irfan Naqvi
Submitted by: Rooha Tanveer

pg. 1
Joins

Question 1:

Part 1:
Find the salesperson and customer who reside in the same city. Return Salesman, cust_name
and city.
Commands & Queries:

Creating Database & Tables:

pg. 2
Inserting Record:

Query:

pg. 3
Table:

Salesman Table:

Customer Table:

Query Result:

pg. 4
Orders Table:

Part a:
SQL statement to generate a report with customer name, city, order number, order date,
order amount, salesperson name, and commission to determine if any of the existing
customers have not placed orders or if they have placed orders through their salesman
or
by themselves.

pg. 5
Commands & Queries
Creating Table and Inserting Record:

Query:

pg. 6
Table:
Orders Table:

Query Result:

Part b:
Write a SQL statement to generate a list in ascending order of salespersons who work
either for one or more customers or have not yet joined any of the customers.
Commands & Queries:

pg. 7
Table:

Part c:
write a SQL query to list all salespersons along with customer name, city, grade, order
number, date, and amount.
Commands & Queries:

Table:

pg. 8
Part d:

Write a SQL statement to make a list for the salesmen who either work for one or more
customers or yet to join any of the customer. The customer may have placed, either one
or more orders on or above order amount 2000 and must have a grade, or he may not
have placed any order to the associated supplier.
Commands & Queries:

Table:

Part e:

For those customers from the existing list who put one or more orders, or which orders
have been placed by the customer who is not on the list, create a report containing the
customer’s name, city, order number, order date, and purchase amount.

Commands & Queries:

pg. 9
Table:

Part f:

Write a SQL statement to generate a report with the customer name, city, order no.
order
date, purchase amount for only those customers on the list who must have a grade and
placed one or more orders or which order(s) have been placed by the customer who
neither is on the list nor has a grade.
Commands & Queries:

pg. 10
Table:

Part g:

Write a SQL query to combine each row of the salesman table with each row of the
customer table.
Commands & Queries:

pg. 11
Table:

pg. 12
Part h:

Write a SQL statement to create a Cartesian product between salesperson and customer,
i.e. each salesperson will appear for all customers and vice versa for that salesperson
who
belongs to that city.
Commands & Queries:

pg. 13
Table:

pg. 14
Part i:

Write a SQL statement to create a Cartesian product between salesperson and customer,
i.e. each salesperson will appear for every customer and vice versa for those salesmen
who belong to a city and customers who require a grade.
Commands & Queries:

pg. 15
Table:

pg. 16
Part j:

Write a SQL statement to make a Cartesian product between salesman and customer i.e.
each salesman will appear for all customers and vice versa for those salesmen who must
belong to a city which is not the same as his customer and the customers should have
their own grade.
Commands & Queries:

Table:

pg. 17
Question 2:

Creating table & Inserting Record in it:

pg. 18
Table:

Part 1:
Following is an example which would delete those records from the table which have age
= 20 and then
COMMIT the changes in the database.
Commands & Queries:

Table:

Part 2:
Delete those records from the table which have age = 20 and then ROLLBACK the
changes in the
database.

Commands & Queries:

pg. 19
Table:

pg. 20

You might also like