You are on page 1of 4

Database Manqemmt Systems (SWE1004)

M. Tech. (lntell'ated) Software En&lneerln&


CAT I Eumlnadon
SLOI' D2 + TD2, Cius Number: 2146
August2016
SOLUTION

PART A (4 ic S = 20)

~-Dl~wsh ~een.a ~e:y and a s~per key. What ls referential integrity constraint? (3+ 2)

Amwer -
" "1 ~key ts a ~t of attributes that can uniquely identify tuples of a relation. Any super set of a key is a super _
__ key. Every key ls a super key but every super key Is not a key. A super key with the minimal number o.f
·-~ttrib\!tes that can uniquely identify tuples of a relation ls a key. A proper subset of a key caMot be a key.
Referential integrity constraint states that a tuple may refer to another existing tuple. f\ tuple
-cannot refer to another tuple which is non-existent.

2. What are the columns that can be left out while entering data into a table? How do you add secondary
key to an existing table? (3 + 2)
Ans_wer
Null column may be left out, column with default may be left out but not null column without default must
be mentioned.
A secondaly key can be added to an existing table using the following SQL command.

The- constraints inherent in a data model are called model-based constraints. In relational data modl l~~of "" ··
- -:::-. .-:-

the model:cbased constraints ls 'attributes must be atomic'.


--~ -::_~ t s deflned on a schema are called schema-based constraints. The domal~ constraints, key
0

--
c..~-~~~~~ -~
- = ~--=-:-- -
--=--
ty J.qtegrlty -constraints and referential Integrity constraints are schema-based _constraints.
- -
_;;..~~ The_doma!n~_!n_! states that value of every attribute should belong to the domain of the attribute, key
-:....~~~-==- _::::;=::~ ·=:..=~~ = -
~t;(!ns~i~~e~ tlf~.:--~
~;,...c;--:: alue_cannot be dupllcated, entity Integrity constraint states. that prlmary key value
~r -=-:~ ot ~ n~I ~n-(~fe~ ti!_lintegrity constraint states that a tuple may refer.to another exlsUng tuple only.
-c: ~-- - t,,ny.con~ ~1hat_~"ei~-:--model,:b_ased nor schema-based ls called semantic co~straint. An example of
- -5'~ tlc ~ns.trabiM"'s~sdlocy-ofan ~inployee cannot exceed s~lary of his/her Immediate supervisor'.
- ~ _- -:: -~ -
"'
.

~- Mention the cQnstrai~ \hat ~yoeylolated during data entry, data modlflcation and c,iata deletion.
Answer
During data -entry -the C0""5traints that may be violated are domain co~traint, entity Integrity constraint, key
constraint and referential integrity constraint.

- - - - -- - - - -- - - - - - --- - - - - --
constraint, entity integrity
During data modification the constraints that may be violated are domain
constraint, key constraint and referential integrity constraint .
constraint.
During data deletion the constraints that may be violated is referential integrity

PART B (3 ,c 10 = 30)

5. Consider the following database schema.

fl!Mlt Miill L._.,


lJEMITMDfT

SpecifythefollowingqueriesinSQL. ~ _ --::-~ ---'C _X-


(a) Retrieve the name of the departments along with !he__!cVerage salary of the -e-
departme ot - - ..::: - = -;=..=-::::- ~ -= - ~

(b) Retrieve _name (first name and last name) of employees along with the n -_
==:!IJBJ!!lf!~~~~~§:::
· _wade for. =- _: -
__ . ___ ..
_(c) _,Retrievgc the name of department and the first name and last name of depclrtm
-- _- {d) R~ieve th;first name and last name of employees whose last name has
an ~-a§ihe-f ~ ~ { 1 f---:--
~___,- Afier ~ -
_::= :__-= ~~~, ~--
by dname;
~ a) select dname,.avg(salary) from employee, department where dno = dnumber group
:c_--,-~

~_;,~ -1b"J; ~ ~me, lname, dname from employee, department where dno = dnumber;
1~~ ?° :-~::-(c),}~~o~ame,-=--fname, lname from employee, department where mgr_ssn = ssn;
:f - =- ~ - =-@)"_s~ ~"ame, from employee where lname like '_e%';

~
~-~---.-.::_-_'_:_:-_---=',·_- ~~
\,
~t~::::~~
:hi~ salacy.~f
~ icentage1;y
. -~· - ~~;;_Jie;, value 'J'1e n~f ~ a1ary i?not -wi>~
fiigb-(not
0
tha's,accepts (as input) social secu,lty number of an employ,. and th<,
this ~ ployee needs to be increased. The salary- should be ul>(lated to the+'.
higher than $70,000) otherwise, a user ~fined ~ceptlO:e
®tabJe §Chema of gue.stion n\llll,ber 5). . (Sl-
;1\;. .:- ':,,.~ouldtbe thrown.(Refor to ColJlpany
-:_ --:··
:!~~:- . . ~::•;~ :~\. . . .
,,.
~~;;

-~~--~~-j_:~--;.":'. .~;~_,, . . ;, , ~. . , .,
·t.: !~
trigger should
ever salary of an employee Is updated. The
(b) Write a database trigger that fires when
y, old salary
d enter a row into a table containing new salar
display the old salary and new salary and shoul
(5)
and the date of salary update.
and social security number of the employee
Amw er
mber) is
(a) create or replace procedure pl(ss char, pc·nu
70000; sal employee.salary%type;
too_high exception; high constant numb er:=
[i
begin
ssn = ss;
selec t salary into saJ from empl oyee where
dbms.:_outputpuLline('Salary is ' II sal);
if sal~ l + pc) > high then raise too_high;
salary"'pc wher e ssn = ss;
else upda te empl oyee set salar y= salar y+
end if;
exception
when too_h igh then
not be upda ted');
raise _app licatl on_e rror(- 2100 0, 'Sala ry could

when other s then


null;

end; .
-
-
(b) creat e table tl_ca t( ff '-=:;--
~~~,= ,.

old_s al numb er(lO , 2),


.':
new_sal number(lO, 2),
ssn char(9),
date_updated date primary key);

create or replace trigg er trg_cat


before upda te of salary on employee
for each row
when (oldsaiary < new.salary}
begin
dbms_outputput_line(:old.salary II' 'II :new.salar
y);
:old.ssn, sysdate);
insert into tl_ca t values(:old.salary, :new.salary,
end;

5.
ra referring to the schema of question number
,1·. Specify ~ foll o~g queries in relational algeb
y higher than $35,000. (2)
.(a) Retrieve first name,
last name and address of employees wid) salar
Immediate
) of employees along with the name· of their
(b) Retrieve ,Dame {first name and last name
(3)
supervisor.
draws
(c) Retrieve:the first_nag:ie_and last name of empi
oyees who work .in Administration department and
(3)
salary higher man$30,000.
3
(2)
(d) Retrieve social security number of employees who do not have dependent.
Answer
(a) 1t (nam,. loam•, adW'H!I (a sal•ry > 35000 (employee))
(b) 1t t.fnamr, t .hwot. s.lname. ~ ( a , .suprr_.... z ...... (p, (employee) X Ps (employee))

(c) 1t INUM, lnamo (a dnome - 'AdminisUOl.i on'A Almy > 30000 (employee l)CI clno=dnumbor department)).

(d) 1t:..., (employee) - ,i: - (employee " , an = un dependent) .

You might also like