0% found this document useful (0 votes)
43 views3 pages

Exp Database Design and Management Lab

The document discusses database design and management. It describes creating two tables, Employees and Departments, with attributes and primary/foreign keys. Values are inserted into the tables. Queries are written to list the count and average salary per department, employee name, department name and salary, and employee name with department manager ID. A function is created to return an employee's salary given their ID, handling exceptions if the ID is not found.

Uploaded by

Bhuvaneshwar A
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views3 pages

Exp Database Design and Management Lab

The document discusses database design and management. It describes creating two tables, Employees and Departments, with attributes and primary/foreign keys. Values are inserted into the tables. Queries are written to list the count and average salary per department, employee name, department name and salary, and employee name with department manager ID. A function is created to return an employee's salary given their ID, handling exceptions if the ID is not found.

Uploaded by

Bhuvaneshwar A
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

DATABASE DESIGN AND MANAGEMENT LAB

2. Create the following tables with given attributes having appropriate data type and specify the
necessary primary and foreign key constraints:
Employee (EmpId, Empname, Sal, Deptno)
Dept (Deptno, Dname, Loc,DeptmanagerId)

Create Table
create table Dept (Deptno varchar(10), Dname varchar(25), Loc varchar(25), DeptmanagerId integer,
constraint pk_dept primary key (deptno) );
create table Employee (EmpId integer, Empname varchar(25), Sal Float(10), Deptno Varchar(10),
constraint pk_emp primary key(empId), constraint fk_deptno FOREIGN KEY (Deptno)
REFERENCES Dept(Deptno));

Inserting Values
INSERT INTO Dept (`Deptno`, `Dname`, `Loc`, `DeptmanagerId`) VALUES ('AI001', 'AI',
"Coimbatore", '11001');
INSERT INTO Dept(`Deptno`, `Dname`, `Loc`, `DeptmanagerId`) VALUES ('CS001', 'CSE',
'Chennai', '12001');

INSERT INTO Employee (`EmpId`, `Empname`, `Sal`, `Deptno`) VALUES ( '1001', 'Bhuvaneshwar',
'12000', 'AI001');
INSERT INTO Employee (`EmpId`, `Empname`, `Sal`, `Deptno`) VALUES ('1002', 'Nithish',
'10000', 'AI001');
INSERT INTO Employee (`EmpId`, `Empname`, `Sal`, `Deptno`) VALUES ('1003', 'Ravi', '5000',
'CS001');
INSERT INTO Employee (`EmpId`, `Empname`, `Sal`, `Deptno`) VALUES ('1004', 'Priya', '15000',
'CS001');

Dept Table Employee Table


Queries
a) List the count of Employees and average salary of each department.

SELECT Deptno, COUNT(EmpId) AS 'Number of Employees', AVG(Sal) AS 'Average


Salary' FROM Employee GROUP BY Deptno;

b) List the employee name, department name and the salary of all the employees.

SELECT Employee.Empname as 'Employee_name', Employee.Sal, Dept.Dname FROM


Employee JOIN Dept ON Employee.Deptno = Dept.Deptno;

c) Display the Employee name and the respective department manager name.

SELECT Employee.Empname, Dept.DeptmanagerId FROM Employee JOIN Dept;


WARNING : Not Having Manager Name So I used ManagerID

d) Create a function to return the salary of the employee when Empid is given as input
parameter. Handle Exceptions.

create or replace function salary (EmpId NUMBER);


temp varchar(20);
BEGIN
SELECT sal INTO temp , sal from Employee WHERE EmpId = EmpId;
EXCEPTION
WHEN no_data_found THEN
dbms_output.put_line('ERROR');
dbms_output.put_line('there is no empid');
End;
/

Output Not Come for This

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy