Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Assignment No:1
Q. 1 Define the working of SQL commands of Data Definition Language, Data Manipulation
language, Data Control Language and Transaction Control Language.
Q. 2 Write about the different data types used in SQL.
Assignment No: 2
Q.1 Create a table employee having following columns:
firstname, lastname, title, age and salary
Q.2 Enter the data of eight employee into employee table.
Q.3 On the basis of employee table answer the following questions:
i) Select all columns for everyone in your emp table.
ii) Select first and last names for everybody thats under 30 year old.
iii) Select all columns for everyone with a salary over 30000.
iv) Select firstname, lastname and salary for anyone with Programmer in their title.
v) Select the firstname for everyone whose lastname contains a.
vi) select all columns for everyone whose firstname starts with D.
Assignment No: 3
Q1. Following relations are given to you.
EMPLOYEE
MPLOYEE_ID
NOT NULL
FIRST_NAME
NUMBER(6)
VARCHAR2(20)
LAST_NAME
NOT NULL
VARCHAR2(25)
NOT NULL
VARCHAR2(25)
PHONE_NUMBER
VARCHAR2(20)
HIRE_DATE
NOT NULL
DATE
JOB_ID
NOT NULL
VARCHAR2(10)
SALARY
NUMBER(8,2)
COMMISSION_PCT
NUMBER(2,2)
MANAGER_ID
NUMBER(6)
DEPARTMENT_ID
NUMBER(4)
Page | 6
EMP_DETAILS_VIEW:
Name
Null?
Type
EMPLOYEE_ID
NOT NULL
NUMBER(6)
JOB_ID
NOT NULL
VARCHAR2(10)
MANAGER_ID
NUMBER(6)
DEPARTMENT_ID
NUMBER(4)
LOCATION_ID
NUMBER(4)
COUNTRY_ID
CHAR(2)
FIRST_NAME
VARCHAR2(20)
LAST_NAME
NOT NULL
VARCHAR2(25)
SALARY
NUMBER(8,2)
COMMISSION_PCT
NUMBER(2,2)
DEPARTMENT_NAME
NOT NULL
VARCHAR2(30)
JOB_TITLE
NOT NULL
VARCHAR2(35)
CITY
NOT NULL
VARCHAR2(30)
STATE_PROVINCE
VARCHAR2(25)
COUNTRY_NAME
VARCHAR2(40)
REGION_NAME
VARCHAR2(25)
DEPARTMENTS:
Name
Null?
Type
DEPARTMENT_ID
NOT NULL
NUMBER(4)
DEPARTMENT_NAME
NOT NULL
VARCHAR2(30)
MANAGER_ID
NUMBER(6)
LOCATION_ID
NUMBER(4)
Page | 7
7>select first_name of employees in the increasing order of salary and if salary matches then decreasing order of
the department_id.
8>Retrieve first_name and depart_id and the salary of all the puchase managers and display them with modified
salary(5% increase in salary rename the coloumn by new_salary) for there good work.
9>Retrieve first_name of all programmers of IT department whose first name starts with a and ends with b.
10> Retrieve first_name of all programmers of IT department whose first name contains a substring all
11>Retrieve all the records except David, Peter,Oliver,Allan.
12>Display all the records of employees in CSV (comma separated file) form under the heading Employee_
Details.
13> There are four coding errors in this statement. Can you identify them?
SELECT employee_id, last_name
sal x 12 ANNUAL SALARY
14) The following SELECT statement executes successfully:
SELECT last_name, job_id, salary AS Sal
FROM employees;
(True / False)
(True / False)
16) There are four coding errors in this statement. Can you identify them?
SELECT employee_id, last_name
sal x 12 ANNUAL SALARY
FROM
employees;
17) Show the structure of the DEPARTMENTS table. Select all data from the table.
18) Show the structure of the EMPLOYEES table.
Create a query to display the last name, job code, hire date, and employee number for each employee, with
employee number appearing first.
Provide an alias STARTDATE for the HIRE_DATE column. Save your SQL statement to a file named
Assignment11.sql.
19) Create a query to display unique job codes from the EMPLOYEES table.
19) Display the last name concatenated with the job ID, separated by a comma and space, and name the column
Employee and Title.
20) Create a query to display the last name and salary of employees earning more than $12,000.
21) Create a query to display the employee last name and department number for employee number 176.
22) Display the employee last name, job ID, and start date of employees hired between February 20, 1998, and
May 1, 1998. Order the query in ascending order by start date.
23) Display the last name and department number of all employees in departments 20 and 50 in alphabetical order
by name.
24) Modify Assignment13.sql to list the last name and salary of employees who earn between $5,000 and $12,000,
and are in department 20 or 50.
Label the columns Employee and Monthly Salary, respectively.
25) Display the last name and hire date of every employee who was hired in 1994.
26) Display the last name and job title of all employees who do not have a manager.
Page | 8
27) Display the last name, salary, and commission for all employees who earn commissions. Sort data in
descending order of salary and commissions.
30) Display the last names of all employees where the third letter of the name is an a.
31) Display the last name of all employees who have an a and an e in their last name.
32) Display the last name, job, and salary for all employees whose job is sales representative or stock clerk and
whose salary is not equal to $2,500, $3,500, or $7,000.
33) Write a query to display the current date. Label the column Date.
34) For each employee, display the employee number, last_name, salary, and salary increased by 15% and
expressed as a whole number. Label the column New Salary. Place your SQL statement in a text file named
lab3_2.sql.
35) Write a query that displays the employees last names with the first letter capitalized and all other letters
lowercase, and the length of the names, for all employees whose name starts with J, A, or M. Give each column an
appropriate label. Sort the results by the employees last names.
36) Create a query that displays the employees last names and commission amounts. If an employee does not
earn commission, put No Commission. Label the column COMM.
37>List the location id, hire date, job id of all the managers
38>List the maximum salary of the Employees.
39>List average salary of each department.
40>List average salary of those departments where total employees are greater than 10.
Assignment No: 4
Q1. Create the following tables:
i)
client_master
columnname
client_no
name
city
state
pincode
bal_due
ii)
datatype
size
varchar2
6
varchar2
20
varchar2
varchar2
15
number
6
number
10,2
15
Product_master
Columnname
Product_no
Description
Profit_percent
Unit_measure
Qty_on_hand
Reoder_lvl
datatype
varchar2
varchar2
number
varchar2
number
number
size
10
10
10
5
5
5
Page | 9
6, 2
6, 2
Name
city
pincode
0001
0002
0003
0004
0005
0006
Ivan
Vandana
Pramada
Basu
Ravi
Amit
Bombay
Madras
Bombay
Bombay
Delhi
Bombay
400054
Maharashtra
15000
780001
Tamilnadu
0
400057
Maharashtra
5000
400056
Maharashtra
0
100001
2000
400050
Maharashtra
0
1.44floppies
Monitors
Mouse
1.22 floppies
Keyboards
CD Drive
540 HDD
1.44 Drive
1.22 Drive
5
6
5
6
2
2.5
4
3
5
piece
piece
piece
piece
piece
piece
piece
piece
piece
state
bal.due
Qty
Reorder
Sell
measured on hand lvl
100
10
20
100
10
10
10
10
2
20
3
5
20
3
3
3
3
3
525
12000
1050
525
3150
5250
8400
1050
1050
Cost
price
price
500
11200
500
500
3050
5100
8000
1000
1000
Q3:- On the basis of above two tables answer the following Questionnaires:
i)
Find out the names of all the clients.
ii)
Retrieve the list of names and cities of all the clients.
iii)
Display the information for client no 0001 and 0002.
iv)
Find all the products whose sell price is greater than 5000.
v)
List the Total clients city wise.
Page | 10
Assignment-5
Q.1
i.
ii.
iii.
iv.
v.
vi.
vii.
viii.
Using the table client master and product master answer the following
Questionnaires.
Change the selling price of 1.44 floppy drive to Rs.1150.00
Delete the record with client 0001 from the client master table.
Change the city of client_no0005 to Bombay.
Change the bal_due of client_no 0001, to 1000.
Find the products whose selling price is more than 1500 and also find the new selling
price as original selling price *15.
Rename the Product No. to PRODUCTNO.
Delete the column unit measured.
Increase the size of Name in Client Master.
Assignments-6
Q.1 Create the following tables:
Sales_master
Columnname
Salesman_no
Datatype
varchar2
6
Sal_name
varchar2
Address
varchar2
City
varchar2
State
varchar2
Pincode
Number
Sal_amt
Number
Tgt_to_get
Number
Ytd_sales
Number
Remarks
Varchar2
*Make a check for sales amount >1000
20
20
20
6
8,2
6,2
6,2
30
Size
Attributes
Primary key/first letter
must start with s
Not null
Not null
Sales_order
Columnname
S_order_no
S_order_date
Datatype
varchar2
Date
Size
6
6
Client_no
Dely_add
Varchar2
Varchar2
25
6
Attributes
Primary key
Primary key reference
clientno of client_master table
Page | 11
Salesman_no
Varchar2
Dely_type
Char
Billed_yn
Dely_date
Char
Date
Order_status
Varchar2
10
Sales_order_details
Column
Datatype
Size
Attributes
S_order_no
Varchar2
Product_no
Varchar2
Primary key/foreign
key references
s_order_no of
sales_order
Primary key/foreign
key references
product_no of
product_master
Qty_order
Qty_disp
Product_rate
Number
Number
Number
8
8
10,2
Insert the following data into their respective tables using insert statement:
Data for sales_man master table
Salesm
an_no
Address
Cit
y
Pin
code
State
Salamt
Tgt_t
o_get
Ytd
Sales
Remar
k
500001
Salesm
an
name
Kiran
A/14
worli
400002
Mah
3000
100
50
Good
500002
Manish
65,narim
an
400001
Mah
3000
200
100
Good
500003
Ravi
P-7
Bandra
400032
Mah
3000
200
100
Good
500004
Ashish
A/5 Juhu
Bo
mb
ay
Bo
mb
ay
Bo
mb
ay
Bo
mb
ay
400044
Mah
3500
200
150
Good
Page | 12
Client no
Dely
type
019001
12-jan-96
0001
019002
25-jan-96
016865
Salesman
no
Delay
date
Orderstat
us
Bil
l
yn
N
50001
Ip
0002
50002
18-feb-96
0003
500003
019003
03-apr-96
0001
500001
046866
20-may-96
0004
500002
010008
24-may-96
0005
500004
20jan-96
27jan-96
20feb-96
07apr-96
22may96
26may96
C
F
F
C
Ip
Product no
P00001
P07965
P07885
P00001
P07868
P07885
P00001
P03453
P06734
P07965
P07975
P00001
Qty ordered
4
2
2
10
3
10
4
2
1
1
1
10
Qty disp
4
1
1
0
3
10
4
2
1
0
0
5
Product_rate
525
8400
5250
525
3150
5250
1050
1050
12000
8400
1050
525
Page | 13
Assignment 7
Q.1. Create the following tables:
Table Name : Challan_Header (Challan no is foreign key and s_order_no is primary key)
Column name
Challan_no
s_order_no
data type
varchar2
varchar2
size
6
6
challan_date
billed_yn
date
char
Attributes
Primary key
Foreign key references s_order_no of
sales_order table
not null
values (Y,N). Default N
data type
varchar2
size
6
number
4,2
Attributes
Primary key/Foreign key references
Product_no of product_master
not null
Q2. Insert the following values into the challan header and challan_details tables:
(i)
Challan No
S_order No
Challan Date
Billed_yn
CH9001
CH865
CH3965
019001
046865
010008
12-DEC-95
12-NOV-95
12-OCT-95
Y
Y
Y
Product No
P00001
P07965
P07885
P07868
P03453
P00001
P00001
P07975
Qty Disp
4
1
1
3
4
10
5
2
Assignment-8
Using the table of assignment 4&5 answer the following Questionnaires.
i.
ii.
iii.
iv.
v.
Assignment-9
Using the table of assignment 4&5 answer the following Questionnaires.
1.
2.
3.
4.
Find out the product which has been sold to Ivan Sayross.
Find out the product and their quantities that will have do delivered.
Find the product_no and description of moving products.
Find out the names of clients who have purchased CD DRIVE
Assignment-10
Consider the following relations:
Student (snum: integer, sname: string, major: string, level: string,age: integer)
Class (name: string, meets at: string, room: string, d: integer)
Enrolled (snum: integer, cname: string)
Faculty (fid: integer, fname: string, deptid: integer)
The meaning of these relations is straightforward; for example, Enrolled has one record per
student-class pair such that the student is enrolled in the class. Level is a two character code
with 4 different values (example: Junior: JR etc)
Write the following queries in SQL. No duplicates should be printed in any of the answers.
i. Find the names of all Juniors (level = JR) who are enrolled in a class taught by Prof. Harshith
ii. Find the names of all classes that either meet in room R128 or have five or more Students
enrolled.
iii. Find the names of all students who are enrolled in two classes that meet at the same time.
iv. Find the names of faculty members who teach in every room in which some class is taught.
v. Find the names of faculty members for whom the combined enrollment of the courses that
they teach is less than five.
Page | 15
Assignment-11
Using the table of assignment 4&5 answer the following Questionnaires.
1. Find the client names who have placed order before the month of may 95.
2. Find out if product 1.44 Drive is ordered by only client and print the client_no name to
whom it was sold.
3. Find the names of client who have placed orders worth Rs.15000 or more.
Assignment-12
1. Apply commit operation on the table client_master and product_master.
2. Apply rollback operation on the table client_master and product_master.
Page | 16