Assign 1

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

ERITAGE INSTITUTE OF TECHNOLOGY

Dept-IT
Subject: Database Management System INFO3114
ASSIGNMENT

 ERD Designing

Problem 1: Sales information system:


A product can be described with a unique product number, product name, manufacturer
name, product rate, selling price, product description. The product can sale to a particular
client and each client have its own unique client number, client name, client addresses,
city, pin code, state and total balance to be required to paid. Each client order to buy
product from the salesman. In the order, it has unique sales order number, sales order
date, client number, salesman number (unique), billed whole payment by the party or not
and its delivery date, total quantity ordered, date of cancel the order. The salesman have
the unique id number, name, addresses, city, pin code, state, and salary of the sales man.

a) Design an Entity Relationship model for the above problem, maintaining all
cardinality, and constraints.

Day1

 Introduction to Database and DBMS


 Creation of table objects +Insertion of records
 Retrieving Data: writing basic SQL SELECT Statements+
Restricting and sorting data

1.a.Create table emp with attributes emp_id, emp_name, hire_date,job_id,salary


and commission
2 a.Show the structure of the emp table. Select all data from the emp table.
b.Create a query to display the name, job_id, hire date, and employee number for
each employee, with employee number appearing first. Provide an alias STARTDATE
for the hire date column.
c.Create a query to display the unique job codes from the employee table.
d.Display the last name concatenated with job id, separated by a comma and space and
name the column Employee and Title.
e.Write a query to find out the annual salary of each employee.

i)Display the names of employees who have an a and an e in their names.


ii) Display the name and job of all employees who do not earn a commission.
iii) Display the last name and salary of employees who earn between $5000 and
$12000,and are in department 10 or 20.Label the columns Employee and Monthly
Salary.
b. Write a query that displays all employee’s whose names starts with J,A or M.
Sort the results by the employees last name.
c. Display the name , job, and salary for all employees whose job is sales representative
or stock clerk and whose salary is not equal to Rs2500 and lies in the range Rs 1000
to Rs. 10000 and department no is 20,50 ,60 and 70.

Home Assignment
1.a)For each employee display the employee number, salary and salary increased by 15
%,Label the column New salary. Place your sql file in a text file and run it.
b) Modify the query to add a column that substracts the old salary from the new
salary. Label the column Increase.
2)Write a query that produces the following for each employee.
<employee last name> earns <salary> monthly but wants <3 times salary>.Label the
column Dream Salaries.

3.a) For each employee, display the employee number, employee name, salary, and
salary increased by 15% and expressed as a whole number. Label the column as New
Salary.
4) Display the name, total monthly salary of each employees i.e. salary along with
commission of all those employees whose name starts with ‘A’ .

Day2

 Defining constraints + NOT NULL constraints + UNIQUE


constraints + PRIMARY KEY constraints + FOREIGN KEY
constraints + CHECK constraints
1. a) Create a table Depart with the columns
dept_id, dept_name, location_name where dept_id is primary key
b) Create another table Employ with the columns empid, name, salary, address,
hire_date, department_no where empid is primary key.
N.B. Make a referential integrity between department_no and dept_id. Also make
sure that salary must contain some values in all rows and each department’s name is
different.
Give appropriate names to all the constraints being imposed on both the tables
Insert at least 3 rows in departments table . Insert at least 5 rows in the employees table
with different department names

2. a) Create a table Departments with the columns


dept_id, dept_name, loc_name where dept_id is primary key.
b) Create another table locations with the columns location_id, location_name, area
where location_id is primary key.
N.B. Ensure that location_name acts as another candidate key of the locations table.
Make a referential integrity between loc_name of departments table and location_name
of locations table.
Give appropriate names to all the constraints being imposed on the tables. Insert
at least three rows in both the tables.
.
3. a) Create a table Employees with the columns empid, name, salary, address,
hire_date, mgr_no,dept_name where empid is primary key.
N.B. Make a referential integrity between emp_id and mgr_no.
Give appropriate names to all the constraints being imposed on the tables.Insert at
least 10 rows in the employees table with different department names(Make one
department name CSE)..

DAY3

 Creating table from different table + The Insert Statement + The


Update Statement + The Delete Statement + The Merge Statement
+ Alter statements + Drop and rename statements

1.a)Create a DEPTT table based on the following table instance chart.Place the syntax in
a script,then execute the statement in the script to create the table.Confirm that the table
is created.
Column name ID NAME
Data Type Number Varchar2
Length 7 25

b) Populate the DEPTT table with data from the DEPARTMENTS table. Include only
columns that you need.

2. a)Create the EMPP table based on the following table instance chart.Place the syntax
in a script. then execute the statement in the script to create the table.Confirm that the
table is created.

Column Name ID LAST_NAME FIRST_NAME DEPT_ID


Data Type Number Varchar2 Varchar2 Number
7 25 25 7

b) Modify the EMPP table to allow for longer employee last names. Confirm your
modification
c) Modify the EMPP table to add a Commission column of number data type,
precision 2.scale 2.
d)Rename the DEPTT table to DEPART.
e) Drop the EMPP table

3) a)Populate the EMPP table with data from EMP table. Check the contents.
Update the last_name of employee 3 to Drexler .Verify your changes to the table.
b) Delete information of all employees whose first_name starts with A.
Confirm your changes.
c) Commit all pending changes.

DAY4

 single row functions +


 Group functions + Displaying data from multiple tables

1.Write a query to display the number of people with the same job.
2.a)Determine the number of managers without listing them.Label the column Number of
Managers
b)Write a query that displays the difference between the highest and lowest
salaries. Label the column Difference.
3. Display the manager number and the salary of the lowest paid employee for that
manager. Exclude anyone whose manager is not known. Exclude any groups where
the minimum salary is $6000 or less. Sort the output in descending order of salary.
4.a)Display the highest,lowest,sum, and average salary of all employees.Label the
columns Maximum, Minimum, Sum, and Average, respectively. Round your results
to the nearest whole number.
b)Modify the query to display the minimum,maximum,sum,and average salary for each
job type.
5)Create a query to display all the data from the employee table. Separate each column by
a comma. Name the column “the_output”.

6)a)Create a query to display the last name and salary for all employees.Format the salary
to be 15 characters long, left padded with $.
b)Display each employees last name and commission amounts.If an employee doesnot
earn a commission put “no commission”.
7) Display the last name,hire date and day of the week on which the employee started.
8) Modify the query and display the name with asterisks and total monthly salary of
each employee in descending order. Here each asterisk signifies 1000. E.g.: So if monthly
salary of employee ‘Abel’ is Rs 24300 then display the name Abel followed by 24
asterisks(because salary is 24thosand and three hundred rupees) like following
NAME SALARY
Abel************************ 24300

DAY5

 Displaying data from multiple tables

1) a)Display the employee name and department name for all employees who have an
a (lowercase) in their last names.
b) Write a query to display the employee name, department name, location id and
city of employees who earn a commission.

2) a)Display the employee name and employee number along with their manager’s name
and manager number. Label the columns employee, emp#, manager, and mgr# resp.
Place your SQL statement in a text file.
b)Modify the above query to display all employees including king who has no
manager.Order the results by the employee number. Place your sql statement in a new
text file
3)a)Create a query that displays employee name, department numbers and all the
employees who work in the same department as the given employee. Give each
column an appropriate label.
b)Create a query to display the name and hire date of any employee hired after
employee Davies.

4) Display the names and hiredate for all employees who were hired before their
managers, along with their manager’s names and hire dates. (Hint: Use self join)

Home Assignment
1) a) Write a query to display the last name, department number, and department name
for all employees.
2) a) Create a unique listing of all jobs that are in department 80.Include the location of
the department in the output.
b) Write a query to display the last name, job, department number, and department
name for all employees who work in Toronto.
3) Write a query to display each department’s name ,location ,number of employees and
the average salary for all employees in that department for those departments where the
average salary is greater than or equal to Rs.10000. Label the columns Department’s
Name, Department’s Location, Number of People and salary, respect

DAY6

 Sub Queries+ correlated subquery


1) Write a query to display the employee numbers and last names of all employees
who earn more than average salary.Sort results in ascending order of salary.
2) a) Write a query that displays the employee numbers and last names of all employees
who work in a department with any employee whose last name contains a u.
b) Modify the query above to display the employee numbers, names, and salaries of all
employees who earn more than the average salary and who work in a department with
any employee with a u in their name. Resave it in another file and run.
3) Display the name,department number, and job id of all employees whose department
location id 1700
4) Display the name and salary of every employee who reports to king.
5) Display the department number, name ,and job id for every employee in the Executive
department.
6) Display the name of the 4th highest paid employee.

Home Assignment
1) Display the department and its average salary whose average salary is minimum among
all the departments.
2) Display employee names and their salary whose salary is greater than at least one
employee of department no 50.
3) Display employee names and their salary whose salary is greater than all employees of
department no 50

DAY7

 System and Object Priviledges


1.a)Create a view called Emp_vu based on the employee numbers,employee names, and
department numbers from the emp table.Change the heading for the employee name to
employee
b) Display the contents of the emp_vu view.
2.a)Create a view named dept50 that contains the employee numbers,employee last
names.and department numbers for all employees in department 50.Label the view
column empno,employee,and deptno.
b) Display the structure and contents of the dept50 view.
c) Reassign employee Matos to department 80
3. Create a view called Salary_vu based on employee last names,department
names,salaries,andd salary grades for all employees.Use the employee,departments and
job_grades tables.
4. Grant another user access to your departments table.Have the user grant you query
access to his or her departments table.
5. Create a synonymn for the other user’s department table
6. Query all rows in the other teams departments table by using your synonym.

 Practice
1a) Refer the Departs table to write a query to display each department’s name,number
of employees and the average salary for all employees in that department for those
departments where the average salary is greater than or equal to Rs.1000.
b) Modify the employ table to add a commission column that ensures that a commission
value is greater than zero.
2b) Write a query to display the name, hire date of all employee hired before their
managers, along with their managers’ name and hire dates
c) Write a query to display the department and its average salary whose average salary is
minimum among all the departments.

4. a) Refer the Employees table with the columns empid, name, salary, address,
hire_date, mgr_no,dept_name where empid is primary key.
N.B. referential integrity between emp_id and mgr_no.
b) Display employee names and their salary whose salary is greater than all employees of
department name ‘CSE’
c) Write a query to display the name and salary of the 5th salaried employee .
DBMS ASSIGNMENT PL/SQL
Update and print message :
1. Write a PL/SQL block of code to update the salary of john and black by 2000 and 5000
respectively. If the total salary is greater than 50,000 then undo the update.
2. The HRD manager has decided to raise the salary of all the employees by 0.15%.
Write a PL/SQL code to accept employee ID and update the salary. Display appropriate
message about the existance of record in emp table.
Cursor:
1. The HRD manager has decided to raise the salary of all the employees in department
20 by 0.05%. The record is maintained in emp_raise table. It includes employee ID, date
of modification, actual raise. Write the PL/SQL code.
2. Write a PL/SQL code that displays the name, department, salary of first 10 employees
getting the highest salary from emp table.
Trigger :
1. Create a trigger to delete data from child table when it is deleted from parent table.
2. Create a transparent audit system for the table client_master. The system must keep
track of the records that are being deleted or updated from the client_master table. When
a record is deleted or updated from the client_master table , the original value is stored in
the client_master_audit table.
Client_master is a table used to store information about clients. Against this table
auditing is performed. The attributes of this table are client_no, name, city, balance.
Client_master_audit table is used to keep track of the records being updated or deleted.
When such operation is carried out, a trigger is fired due which records are inserted in the
client_master_audit table. The attributes of client_master_audit table are client_no,
operation, name, balance, user, date.
Write the PL/SQL code.
3. Write a program in PL/SQL that will automatically update the child table if the parent
table gets updated.
Cursor and Trigger:
1. Write a program using cursor and trigger to insert a new record into the parent table if
anybody tries to inset a record in the child table. Once the event of inserting a new record
into the child table happens, then your program should first find out if that record is
present in the parent table or not. If not then it will first insert in the parent table and then
perform the event.

Procedure:
1. Write a PL/SQL code using procedure to find the minimum of three numbers.
2. Write a PL/SQL code using procedure to find the square of a number.
3. Write a PL/SQL code using procedure to print greetings.
Exception :
1. Insert data from 1 to 100 in a table. Take input from the user that which record it
doesn’t want to insert and create exception for it.
2. Create an exception against inserting duplicate record in a table.

PROJECT (Backend Development with user interactivity via PL/SQL)

1. Create an online Course Enrollment System having the following criteria.


a) User has to register themselves for viewing the courses available. Thus both
registration and login facilities should be provided.
b) User has the option to enroll in one course only.
c) Each course has a maximum intake capability of 40. Once 41th candidate tries to enroll
for a particulat course, it will display " No vacancy in this course".

2) Design a Railway Reservation System maintaining the following features.


User will have to register themselves and next login.
User can view the trains available after provoding the Source, Destination.
Users can check availability of train after logging in, by providing source, destination,
date-of-journey, type of compartment.
Once, available user can book a train by proving some other details.

You might also like