You are on page 1of 5

Duy Tan University MID TERM Code:

International School Course: Information Systems Application 01

Programs: CMU Classes: CMU-IS 401-SC

School year :2020 -2021

Duration: 90 minutes

FULL NAME: Nguyễn Thị Mỹ Trinh CLASS: CMU-IS 401-SC

1. Consider the following relational schema and briefly answer the questions that follow:

EMPLOYER(ID_EMPL, NAME, PHONE, ID_DEPT)

DEPARTMENT(ID_DEPT, NAME)

Write the function that calculates the total number of employees when entering the department code
value

-> if object_id('fSumnv','FN') is not null

drop function fSumnv;

Go

Create function fSumnv(@id_phong nvarchar)

returns int

As

Begin

return (select count(ID_DEPT)

From EMPLOYER where ID_DEPT=@id_phong)

End

Go

print dbo.fSumnv('P02');

2. KHACH(MAKHACH, TENKHACH, DIACHI)

PHONG(MAPHONG, TENPHONG, LOAIPHONG)

PHIEUDATPHONG(SOPHIEU, NGAYDATPHONG, MAKHACH, SOPHONG)


No 2 Page 1
CHITIETDATPHONG(SOPHIEU, MAPHONG, NGAYDEN, NGAYDI, GIA)

Write a transaction to aggregate amount for each customer (Have use Isolation level)

-> create proc PR_AGGREGATE @makhach nvarchar(10)

as

begin begin transaction

set transaction isolation level read uncommitted select TENKHACH, datediff( dd, NGAYDEN, NGAYDI ) * GIA *
SOPHONG

As

TOTAL of MONEY

from KHACH k, PHIEUDATPHONG p, CHITIETDATPHONG ct

where (k. MAKHACH = p. MAKHACH)

and

(p. SOPHIEU = ct. SOPHIEU)

and

(k. MAKHACH = @makhach )

commit transaction

end

3. Consider the following schema:

Suppliers(sid: integer, sname: string, address: string)

Parts(pid: integer, pname: string, color: string)

Catalog(sid: integer, pid: integer, cost: real)

3.1. Define a table constraint on Catalog that will ensure that all cost > = 0

-> create table Catalog(

sid int not null,

pid int not null,

cost real ,

CONSTRAINT cost CHECK (cost >= 0),

PK_kh primary key(sid,pid),


No 2 Page 2
constraint FK_sid foreign key(sid) references Suppliers(sid),

constraint FK_pid foreign key(pid) references Parts(pid) )

3.2. Find the pids of parts supplied by at least two different suppliers.

-> SELECT c.PID COUNT(*)

AS

TOTAL FROM SUPPLIERS s, PARTS p, CATALOG c

WHERE

(s.SID = c.SID) AND (c.PID = p.PID)

GROUP BY

c.PID HAVING COUNT(*) > 1

4. Database security

User Jane, who is the owner of the MovieSchema schema that contains tables

MOVIE( Title, Year, Length, InColor, StudioName, ProducerID)

STUDIO (Name, Address, PresID)

4.1. Grant the INSERT and SELECT privileges on table STUDIO and privileges
SELECT on MOVIE to users Mary and Kird. Moreover, she includes the grant
option with these privileges

->
GRANT INSERT,

SELECT ON STUDIO TO Mary, Kird

WITH GRANT OPTION;

GRANT

SELECT ON MOVIE TO Mary, Kird

WITH GRANT OPTION;

4.2. Kird grant to use Peter the same privileges, but without the grant option

->
GRANT INSERT,

No 2 Page 3
SELECT ON STUDIO

TO Peter;

GRANT

SELECT ON MOVIE TO Peter;

Instructor, Duy Tan University

M.Sc Nguyen Thi Thanh Tam

No 2 Page 4
No 2 Page 5

You might also like