You are on page 1of 7

Data Base Management System Lab assignment

Write the queries to create following tables


Table 1: Dept_master

Field Name Data type Size Constraint


Dept_no Varchar2 5 Primary key/Start with ‘d’
Department_Name Varchar2 25
Department_Location Varchar2 30

Table 2: Employee_master
Field Name Data Type Size Constraint
Employee_no Varchar2 6 Start with ‘e’
Employee_name Varchar2 30
Address1 Varchar2 30
Address2 Varchar2 30
DateofBirth Date
Basic Number 6,2
Commission Number 6,2
Dept_no Varchar2 5 Depentdent on dept_no of dept_master
Designation Varchar2 6 Default ‘mstaff’ values if any can be any of
‘cman’, ’vp’, ’mgr’, ‘slman’ and ‘mstaff’

Table 3: Vendor_master
Field Name Data type Size Constraint
Vendor_id Varchar2 6 Primary key/ start with ‘v’
Vendor_name Varchar2 25
Address1 Varchar2 25
Address2 Varchar2 25
City Varchar2 20
State Varchar2 15
Pincode Number 6
Phone number 10

Table 4: Material_master
Field Name Data type Size Constraint
Material_id Varchar2 6 Primary key/ start with ‘m’
Material_desc Varchar2 25
Unit_price Number 6,2
Unit_ measure Varchar2 6
Stock number 3

Table 4: Order_master

Field Name Data type Size Constraint


Vendor_id Varchar2 6 Dependent on vendor_id of vendor_master
Material_id Varchar2 6 Dependent on material_id of material_master
Quantity_ordered number 4 Greater than zero
Date_ordered Date Default system date
Order_id Varchar2 6 Primary key start with ‘o’
Sell_price number 6,2 Greater than zero
Employee_no Varchar2 6
Delivery_status Char 1 Default ‘p’ can have value ‘f’ or ‘p’
Qty_delivered number 4 Less than quantity_ordered and greater than zero

Unit Topics Identified Suggested Problems

V Use of Primary Key & Modify the structure of the employee_master table to have
foreign key Through primary key constraint on the filed employee_no.
Alter

Q. Modify the structure of order_master table to have foreign


key constraint on the field employee_no.

Use of BETWEEN, IN, Q. Write a query to select the vendor id, name and phone no. of
LIKE,NOT IN through vendor who lives in the state of u.p.
where clause in select

Q. Write a query to select the name and address of vendor


whose name contain the letter ‘a’.

Q. Write a query to count the no. of vendors who fall in the state
of “uttar pradesh” If the no. of vendors in the state of uttar
pradesh are 3, the result should be as :
RESULT

-------------

No. of vendors in the state of uttar pradesh is 3.

Q. Write a query to select the vendor id, name and state of the
vendor whose assress2 field has a ‘.’ Contained in it.

Q. Write a query to list the details of vendors who does not


belong to the state of “uttar Pradesh” and “rajasthan”

Q. Write a query to list the material id, its description and stock
available for those whose unit price falls above 600 but less than
900.

Q. Write a query to display the information of a material whose


unit price is either 450.25 or 500 or 700 or 900.

Q. Write a query to display the information about the material


value in the stock is less than 5.

VI Q. Write a query to change the address1 of vendor to “186,


Use of Update Command
circular no. 2” whose vendor id is v1001.

Q. Modify the date of birth to 23-aug-67 where employee id is


e10126.

Q. Write a query to inform you about the vendor(s) in the


following form :- (e.g.)

INFORMATION

----------------------
Vendor with id as v1001 lives in the state of uttar
Pradesh.

Q. Write a query to display the names of all employees whose


Use of And operator
commission is more than 10% of their basic salary and falls
in Select : in the category of salesman.

Q. Write a query to select the employee no. and name of those


Use of Sub Query: employees who earn salary more than the average salary of all
the employees working in the organization.

Q. Write a query to select the minimum, maximum and


Use of function average salary of the employees working in the organization.
MAX ,MIN,AVG: The headings should be smi, smx and sav respectively.

Q. Write a query to display the employee id, name and


department no. of all employees who are either working as
Use of Group by
salesman or miscellaneous staff. The grouping should be
and Order By
department wise. Within the department, it should have all
salesman together and all miscellaneous staff together.

Q. Write a query to inform you about the no. of employees


working for each department.

Q. Write a query to select the name, department name and


location of employee who are designated as manager.

VII
Use of Joins: Q. Write a query to display the name, designation, department
name and location who does not work in the Kanpur office.

Q. Write a query to list the name and id of all employees


in alphabetical order of their name.

Q. Write a query to select the name and date of birth of those


employees who are born before February 7, 1976.

Q. Write a query to select the name and department of those


employees who have age between 30 and 40 years.

Q. Write a query to select the name and basic salary of


employees who have a letter ‘e’ or‘s’ in their names. Further,
modify the query list for those who does not contain ‘m’ in their
names.

Q. Write a query to list the id, name and department no. of


employees who are born in the month of February.

JOINS Display employee names, department number


and department names for all departments
including the department in which no employee
is currently working.

Write a query to list the employee detail along


with the department detail using left Outer join.

Write a query to list the employee detail along


with the department detail using right Outer
join.

Display all rows in the EMPLOYEE table , even if


there is no match in the DEPT table .It also
retrieve all rows in the DEPT table, even if there
is no match in the EMP table.

Display the employee name and number along


with their manager’s name and manager
number.

Display all employees including King, who has no


manager. Order the results by the employee
number.
Create a query that displays employee names,
department numbers, and all the employees
who working the same department as a given
employee. Give each column an appropriate
label.

VIII PL/SQL Create a PL/SQL block that selects the maximum


department no from DEPT table and store it in a
variable. Print the output on the screen.

Create a PL/SQL block that computes the


commission amount for a given employee based
on the employee salary. Accept the employee
number as user input. If sal<1000 then
comm=10% of sal, if sal>=1000 and sal<=1500
then comm=15% of sal, if sal>1500 then
comm=20% of sal . Update the emp table with
new commission amount for the employee.

Write a pl/sql code to display record of


employees E0003 and E0005 using cursors and
display appropriate message for record found
and not found.

Write a pl/sql code to fire a trigger before


insertion of a record in EMP table. The user
should not be allowed to insert any record on
Wednesday.

Write a pl/sql code to fire a trigger before


deletion of a record from EMP table. The user
should not be allowed to delete the record if
salary =1000.
Write a PL/SQL procedure that accepts the
salary of employee from the user and add
Rs.2000/- to the salary of all employees having
salary less than the entered salary.

Write a PL/SQL code to calculate the area of a


circle for a value of radius varying from 3 to 7.
Store the radius and the corresponding values of
calculated area in an empty table named Areas,
consisting of two columns Radius and Area.

Write a PL/SQL code that will reverse a given


number like 12345 to 54321

You might also like