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

DBMS 7

Create the following relations, for an investment firm


emp( emp-id ,emp-name, address, bdate)
Investor( inv-name , inv-no, inv-date, inv-amt)

An employee may invest in one or more investments, hence he can be an investor.


But an investor need not be an employee of the firm.
Create the Relations accordingly, so that the relationship is handled properly and
the relations are
in normalized form (3NF).
Assume appropriate data types for the attributes. Add any new attributes , as
required by the
queries. Insert sufficient number of records in the relations / tables with
appropriate values as
suggested by some of the queries.

Create table emp2(


emp_id int primary key,
emp_name varchar(20),
address text,
bdate date
);

create table investor


(
inv_name varchar(30),
inv_no int primary key,
inv_date date,
inv_amt numeric(8),
emp_id int,
constraint fk foreign key(emp_id) references emp2(emp_id) on delete cascade on
update cascade
);

1.List the distinct names of customers who are either employees, or investors or
both.
select emp_name from emp2,investor
where emp2.emp_id=investor.emp_id
union all select emp_name from emp2;

2.List the names of customers who are either employees , or investors or both.
select emp_name from emp,investor
where emp2.empid=investor.emp_id
union select emp_name from emp2;

3. List the names of emloyees who are also investors.


select emp_name from emp2 Intersect
select emp_name from emp2,investor
where emp2.emp_id=investor.emp_id;

4.List the names of employees who are not investors.


select emp_name from emp2
except select emp_name from emp2,investor
where emp.emp_id=investor.emp_id;

You might also like