Exp Database Design and Management Lab
Exp 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');
b) List the employee name, department name and the salary of all the employees.
c) Display the Employee name and the respective department manager name.
d) Create a function to return the salary of the employee when Empid is given as input
parameter. Handle Exceptions.