Вы находитесь на странице: 1из 11

Practical 1

Create the tables described below(donot draw the tables)


Tablename: client _master

Column name Datatype Size Attributes


Clientnum Varchar2 6 Primary
key/first letter
must start with
‘c’
Name Varchar2 20 Not Null
address Varchar2 20
City Varchar2 20
Pincode Varchar2 15
State Varchar2 15
Baldue Number 10,2
Table name: product_master

Column name Datatype Size Attributes


Productnum Varchar2 6 Primary
key/first letter
must start with
‘P’
Description Varchar2 20 Not Null
Profit _percent Varchar2 20 Not Null
Qty_on_hand Varchar2 20 Not Null
Sellprice Varchar2 10,2 Not Null
Costprice Varchar2 10,2 Not Null,
cannot be 0
Reorderlvl Number 8 Not Null,
cannot be 0
Tablename: salesman_master

Column name Datatype Size Attributes


salesmanno Varchar2 6 Primary
key/first letter
must start with
‘S’
sname Varchar2 20 Not Null
salaryamt Number 8,2 Not Null,
cannot be 0
Qty_on_hand Varchar2 20 Not Null
Remarks Varchar2 50
Table name: sales_order

Column name Datatype Size Attributes


Orderno Varchar2 6 Primary key/first letter must
start with ‘O’
Clientnum Varchar2 6 Foreign key reference
clientnum of client_master
table
salesmanno Varchar2 6 Foreign key reference
salesmanno of
salesman_master table
Dely_type Char 1 Delivery:part(p)/full(f)
Order_status Varchar2 10 Values in (‘in
process’,’fulfilled’,’cancelled’)

Table name: sales_order_details

Column name Datatype Size Attributes


Orderno Varchar2 6 Primary
key/first letter
must start with
‘O’
Productnum Varchar2 6 Foreign key
reference
Productnum
product_master
table
Oty_ordered Number 8
Otydispatch Number 8
Product_rate Number 10,2
Practical 2
Generate SQL statements to perform the following computations on
the table data
1. Listing of the names of all clients having ‘a’ as the second letter
in their names
2. List of all clients who stay in ‘Bangalore’ or ‘Mumbai’
3. Calculate the average ,maximum, minimum for all the product
prices
4. Count the number of product having price greater than or
equal to 500
SQL statements for date manipulation
1. Find the date,15 days after today’s date
2. Display the order number and day on which clients placed
theirs order
SQL statements for using Having and Group By clause
1. Printing the description and total quantity for sold for each
product
2. Calculating the average quantity sold for each client that has a
maximum order value(order value=qtyordered*productRate)
of 1500
Exercises on Joins
1. Find the names of clients who have purchased ‘Trousers’
2. List the products and their quantities for the orders placed by
clientno ‘c0001’ and ‘c0002’
SQL statements for Sub-queries
1. Find the names and address for the customer who has placed
order number ‘o1001’
2. Find the names of the clients who have placed orders worth
Rs.10000 or more
Exercise on updating, altering table structure and deleting table
1. Change the city of clientNo ‘C00005’ to ‘Bangalore’
2. Delete all products from Product_Master whose salaries are
equal to 3500
3. Add a column called ‘Telephone ’ of data type ‘number ’ and
size =’10’ to the client_master table

Practical 3
Customer (cust_id, Lname, Fname, Area, phone)
Movie (Mvno, Title, Type, Star, Price)
Invoice (Invno, Mvno, Custid, Issue date, Return date)
Generate SQL statements to perform the following computations on
the table data
1. Find the movies that cost more than 159 and also find the cost
as original cost * 15
2. Print the names and types of all the movie except horror
movies
3. Find out number of movies in each type
4. Display the title, Lname, Fname for customers having movie
number greater than or equal to three in the following format.
The movie taken by { Fname} { Lname} is { Title}

SQL statements for date manipulation


1. Display the month(in alphabets) in which customers are
supposed to return the movies
2. Delete all the records having return date before 10th July ‘05
Exercises on Joins
1. Find out Lname, Fname and mvno of customers who have been
issued a movie.
2. Find out which customers have been issued movie number
(Mvno) 9.
SQL statements for Sub-queries
1. Find the names of customers who have been issued movie of
type ’ drama’
2. Find out the movie number which has been issued to customer
whose first name is ‘IVAN’
Practical 4
Sales_Header (OrderNo, OrderDate, CustomerID, Salesmanid,
PaymentStatus, TransactionType)
Sales_Detail (OrderNo , ProductID , Qty , Rate , Amt)
Emp (Empid, ename, city, CompID, salary, Joindate)
Company (CompID, CompName, City)

Generate SQL statements to perform the following computations on


the table data
1. Display the various types of product sold to Customers
2. Display the unpaid orders in ascending order of orders.

SQL statements for using Having and Group By clause


1. Display how many male and female members have joined in
January 2004.
2. Display the total number of companies located in each city.
SQL statements for date manipulation
1. Display how many male and female members have joined in
January 2004.
2. Display all Credit transaction, with their payment status done
in December 2003
Exercises on Joins
1. Display the order number, order date, customer name and
order amount for orders
2. Display the order detail where RIN001 soap is sold for Min of
50 Rs.
SQL statements for Sub-queries
1. Give name of companies located in those cities where ‘TATA’
is located.
2. Display the details of books whose price is more than the
average price of all books.

Exercise on updating, privileges


1. Update salary of employee ‘Raj’ by giving him the salary of
‘Radha’ working in same company.
2. Assign the privilege to see the data from both tables to ’Raj’

Practical 5
CATALOG (Book_id primary key, title, author_id foreign key
reference AUTHOR(author_id),publisher_id foreign key reference
PUBLISHER(publisher_id),category_id foreign key reference
CATEGORY(category_id),year, price)
AUTHOR (author_id primary key, name, city, country)
PUBLISHER (publisher_id primary key, name, city, country)
CATEGORY (category_id primary key, description)
MEMBER (member_id primary key, name, address, city, state, pin,
phone, email)
ORDER_SUMMARY (order_no primary key, member_id foreign key
reference MEMBER (member_id), order_date, amt, order_status)
ORDER_DETAILS (order_no foreign key reference
ORDER_SUMMARY (order_no), Book_id foreign key reference
CATALOG (book_id))
Exercises on Joins
1. List the titles ,author’s names, publisher’s name and year for
the books which are published in year 1993 or 1996 or 1998
2. List the titles and names of the authors of the books whose
publisher’s name begins with M
SQL statements for Sub-queries
1. List the title and price of all books whose price is greater than
average than average price of the books having description
‘business’ in the CATEGORY table
2. List the ID, Address, city, state and Pin of all members who
placed an order for the book ‘SQL Complete Reference’
Exercise on updating, altering table structure and deleting table
1. Delete all the books whose price is greater than the average
price
2. Increase the price by 10% for the books published by
‘Microsoft Press ’
3. Change the data type of the column Phone of MEMBER table to
number

Exercise on views and security Management in SQL


1. Create a view BOOK with the columns CATALOG
_ID,TITLE,AUTHOR,PUBLISHER,YEAR and PRICE
2. Grant all privilege on MEMBERS table to user ‘Sam’ allowing
him to pass the permissions to other users
3. Revoke all the privilege on table PUBLISHER from user ‘Mark’
Practical 6
Generate SQL statements to perform the following computations on
the table data
Employee (ecode, ename, salary, status, deptno, city)
Department (deptno, dname, city)
Product (pno, sno, pname, unit_price)
1. Display details of employees XYZ & ABC and any other
employee from department P1
2. List employees who is getting highest salary
3. Select employees whose salary is less than the salary of highest
paying employee from department ‘DS’
4. List the names of employees with their department names
5. Get the second maximum salary of employee table
6. List all unique cities where department locates and /or where
employee

Practical 7
Book (title, author, publisher, category, year, price)
Distributer (dist_id, distributor, city, discount, credit)
Orders (order_no.title, dist_id, quantity)
1. Get the details of all the books whose price is greater than the
average price of the books
2. Get the names of all distributors who are supplying the books
titled ’software testing ’ to the bookshop
3. Get the details of all distributors who give more discount than
the average discount
4. Get the details of all the books whose price is greater than the
maximum of the category average
5. Get the names of all distributors who are supplying the books
author is ‘McConnel’(use nested subquery)
6. Grant the select ,delete & update authority on BOOK table to
user ‘Alex’ with capability to grant those privileges to the other
users
7. Remove all privileges on BOOK table from user ‘Sam’

Practical 8
Workers (worker_id, fname, lname, email, hiredate, salary,
manager_id, commission_pct)

Sections (section_id, section_name, manager_id, area_id)

Area (area_id, area_name, city)


1.Write a query that produces the following for each worker:-
<worker last name> earns <salary> monthly but wants <3 times
salary> label the column Dream Salaries

2.List the section ID and section name of all the section from the
SECTIONS table, regardless of whether or not they belong to any
section or not

3.Display the details of the Worker ID,last name and section ID of


those workers who live in cities whose names begins with T

4.Display the last_name and hiredate of any worker hired after


worker with last_name=’yadav’

5.List all the workers having salary more than 30000 and joined in
the month of January

6.Display the last names of the workers who earns less than the
average salary in their sections

7.Display the worker last name, section nam,e Area Id, and city of all
workers who earn a commission

8.Create a view WORKERS_VU based on the workers ID, worker’s


last names and section IDs from the WORKERS table .Change the
heading for the worker’s name to EMPLOYEE

Вам также может понравиться