dbms calicut university B. sc Cs 4th sem.pdf

Shinana2 441 views 11 slides Jun 10, 2024
Slide 1
Slide 1 of 11
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11

About This Presentation

Its a seminar ppt on database management system using sql


Slide Content

DBMS
SEMINAR
SHINANA UZHUNNAN
27 MAY, 2024
201

Q 8
Consider the employee database given below. Give an expression in SQL for each of the following queries:
EMPLOYEE (Employee-Name, City) WORKS (Employee-Name, Company-Name, Salary) COMPANY (Company-Name,
City) MANAGES (Employee-Name, Manager-Name)
EMPLOYEE (Employee-Name, City)
create table employee(empname varchar(20) primary key,city varchar(20));
COMPANY (Company-Name, City)
create table company(company_name varchar(20) primary key,city varchar(20));
WORKS (Employee-Name, Company-Name, Salary)
create table works(empname varchar(20) primary key references employee(empname),cname varchar(20) references
company(company_name),salary int);
MANAGES (Employee-Name, Manager-Name)
create table manages(empname varchar(20) references employee(empname),manager_name varchar(20) references
employee(empname),primary key(empname,manager_name));
Table Creation

insert into employee values('Swathi','Kozhikode'),('Vishnu','Trivandrum'),('Shreya','USA'), ('Adam','Dubai'),('Sajid','Malappuram');
select * from employee;
insert into company values('Infosys','Trivandrum'),('Chandrika','Trissur'),('Wipro','Kochi'), ('Tata','Mumbai'),('Bajaj','Delhi');
select * from company;
insert into works values('Swathi','Infosys',10000),('Vishnu','Infosys',15000), ('Shreya','Wipro',71500,('Adam','Infosys',8000),
('Sajid','Wipro',18000);
select * from works;
insert into manages values('Swathi','Adam'),('Vishnu','Adam'),('Sajid','Shreya');
select * from manages;
insertion to tables

A) Find the names of all employees who work in Infosys
B) Find the names and cities of residence of all employees who works in Wipro
C) Find the names, and cities of all employees who work in Infosys and earn
more than Rs. 10,000.
D) Find the employees who live in the same cities as the companies for which
they work.
E) Find all employees who do not work in Wipro Corporation.
F) Find the company that has the most employees.

A)
B)
C)
D)

E)
F)

Q 14
Create a function to check whether a given number is prime or not
create or replace function prime(n int)
returns varchar(25) as $$
declare i int;
begin if n<2 then return n ||'is not a prime no';
end if;
for i in 2..n/2 loop if mod(n,i)=0 then return n ||'is not a prime
no';
end if;
end loop;
return n||'is a prime no';
end;
$$ language plpgsql;
select prime(5);

Thank You
SHINANA UZHUNNAN