You are on page 1of 3

SQL HW Assignment

In this assignment, we will use the SQL SERVER 2008 relational DBS!
"his assignment in#ol#es im$lementation an% &uer'ing o( a relational %ata)ase *alle% the +om$an' using
SQL SERVER! "he s*hema with un%erline% $rimar' ,e's is shown )elow! -."E/ )e(ore attem$ting this
$ro)lem ma,e sure that 'ou %o not ha#e e0isting ta)les with i%enti*al names )e*ause SQL will -."
allow 'ou to *reate ta)les with i%enti*al names! I suggest 'ou rename the e0isting ta)le or %elete it!
EMPLOYEE
1-AE I-I" L-AE SS- BDA"E ADDRESS SE2 SALAR3 S45ERSS- D-.
DEPARTMENT
D-AE D-4BER 6RSS- 6RS"RAR"DA"E
DEPT_LOCATIONS
D-4BER DL.+A"I.-
PROJECT
5-AE 5-4BER 5L.+A"I.- D-4
WORKS_ON
ESS- 5-. H.4RS
DEPENDENT
DE57 DE5E-DE-"-AE SE2 BDA"E RELA"I.-SHI5 ES S-
Legend/
De$artment 7 is %esignate% Dnum)er, Dno, or Dnum
Em$lo'ee ID is %esignate% as SS-, Su$erssn, or Essn
5ro8e*t 7 is %esignate% as 5num)er, or 5no
"he *o$' o( this %ata)ase is shown on the (ollowing $age! "o sa#e 'ou some time, a s*ri$t with +REA"E
"ABLE an% I-SER" I-". *omman%s to *reate an% $o$ulate all )ut one relation has )een set u$ (or 'ou
on another a**ount! "he relation DE5E-DE-" is the onl' one whi*h will not )e *reate% automati*all' )'
running the $re$are% s*ri$t! 3ou will nee% to *reate an% $o$ulate the DE5E-DE-" ta)le using SQL
+REA"E "ABLE an% I-SER" I-". *omman%s! 9DE5E-DE-" ta)le sna$shot is lo*ate% on $age 8:!
5lease re(er to the )oo, a)out the (ormats o( these two .RA+LE SQL *omman%s!
A(ter setting u$ all si0 relations 9(i#e )' running the s*ri$t an% one )' *reating an% running 'our own
SQL *omman%s: e0e*ute SQL *omman%s to $er(orm the (ollowing &ueries/
;! What is the total salar' o( all (emale an% male em$lo'ees *om)ine%< "he total *olumn shoul% )e
la)ele% "otal Salar'!
2! Whi*h em$lo'ees wor,e% on two or more $ro8e*ts< Re$ort must in*lu%e em$lo'ees= (irst an% last
name!
>! List the (irst an% last names o( em$lo'ees who ha#e a %e$en%ent with the same (irst name as
themsel#es!
?! Retrie#e the (irst an% last names o( em$lo'ees in %e$artment @ who wor, A hours or more $er wee,
;
on the B5ro%u*t 3B $ro8e*t! "he re$ort must in*lu%e a %e$artment name *olumn!
@! List the (irst an% last name an% SS- o( em$lo'ees who ha#e no %e$en%ents!
C! 1in% the (irst an% last names o( em$lo'ees who are -." %ire*tl' su$er#ise% )' B1ran,lin WongB!
A! 1or ea*h $ro8e*t, list the $ro8e*t name an% the total hours $er wee, 9)' all em$lo'ees: on that $ro8e*t!
"he re$ort must ha#e the $ro8e*t name an% the total hrs! "he total hours *olumn shoul% rea% total hrs
wor,e% an% the $ro8e*t name *olumn shoul% rea% $ro8e*t name!
8! Retrie#e the (irst an% last names an% SS- o( em$lo'ees who %o not wor, on an' $ro8e*t!
D! 1or ea*h %e$artment, retrie#e the %e$artment name an% the a#erage salar' o( em$lo'ees wor,ing in
that %e$artment! "he salar' *olumn shoul% )e la)ele% Em$ A#g Salar' an% %e$t *olumn as De$artment!
4se Notepad to write 'our SQL *o%e an% then *o$' an% $aste it into SQL &uer' win%ow!
HOW TO PRESENT YOUR RESULTS: USE THE EXACT ORDER SHOWN ELOW
!o" ea#$ p"o%&e' do t$e (o&&o)*ng:
+, L*-t and n.'%e" ea#$ /.e-t*on a- -$o)n on t$e a--*gn'ent -$eet
0, S$o) t$e /.e"1 -tate'ent- and t$e "e-.&t- .-*ng a -*ng&e -#"een -$ot (o" ea#$ /.e-t*on, Ma2e
-."e t$e &e(t pane3 t$e /.e"13 and t$e "e-.&t- a"e a&& 4*-*%&e, T$e &e(t pane -$o.&d d*-p&a1 t$e
ta%&e na'e-, Po*nt- )*&& %e ded.#ted (o" *gno"*ng t$e-e d*"e#t*on-,
WARNING: you are not allowed to use information in your SQL code that was not given in the
prolem! A good e"ample is using someone#s SSN when only their name is given to you in the
prolem! $very time this instruction is violated% even when the program returns the right results% you
will loose &'( of the points! In the real worl% it is unrealisti* to sear*h through millions o( re*or%s to
(in% someone=s SS-! In some instan*es this in(ormation ma' )e $rote*te% an% o(( limits to 'ou!
EMPLOYEE
!NAME MINIT LNAME SSN DATE ADDRESS SEX SALARY SUPERSSN DNO
Eohn B Smith ;2>?@CA8D 0DFEA-F@@ A>; 1on%ren, Houston, "2 >0000 >>>??@@@@ @
1ran,lin " Wong >>>??@@@@ 08FDE+F?@ C>8 Voss, Houston, "2 ?0000 888CC@@@@ @
Ali*ia E Gela'a DDD88AAAA ;DFE4LF@8 >>2; +astle, S$ring, "2 1 2@000 D8AC@?>2; ?
Eenni(er S Walla*e D8AC@?>2; 20FE4LF>; 2D; Berr', Bellaire, "2 1 ?>000 888CC@@@@ ?
Ramesh H -ara'an CCC88???? ;@FSE5F@2 DA@ 1ire .a,, Hum)le, "2 >8000 >>>??@@@@ @
Eo'*e A English ?@>?@>?@> >;FE4LFC2 @C>; Ri*e, Houston, "2 1 2@000 >>>??@@@@ @
Ahma% V Ea))ar D8AD8AD8A 2DFARF@D D80 Dallas, Houston, "2 2@000 D8AC@?>2; ?
Eames E Borg 888CC@@@@ ;0F-.VF2A ?@0 Stone, Houston, "2 @@000 -4LL ;
DEPARTMENT
DNAME DNUMER M5RSSN M5RSTARTDATE
Resear*h @ >>>??@@@@ 22FA3FA8
A%ministration ? D8AC@?>2; 0;FEA-F8@
Hea%&uarters ; 888CC@@@@ ;DFE4-FA;
DEPT_LOCATIONS
DNUMER DLOCATION
; Houston
? Sta((or%
@ Bellaire
@ Sugarlan%
@ Houston
PROJECT
PNAME PNUMER PLOCATION DNUM
5ro%u*t2 ; Bellaire @
2
5ro%u*t3 2 Sugarlan% @
5ro%u*tG > Houston @
+om$uteriIation ;0 Sta((or% ?
ReorganiIation 20 Houston ;
-ew)ene(its >0 Sta((or% ?
WORKS_ON
ESSN PNO HOURS
;2>?@CA8D ; >2!@
;2>?@CA8D 2 A!@
?@>?@>?@> ; 20
?@>?@>?@> 2 20
>>>??@@@@ ; ;0
>>>??@@@@ 2 ;0
>>>??@@@@ > ;0
>>>??@@@@ ;0 ;0
>>>??@@@@ 20 ;0
>>>??@@@@ >0 ;0
DDD88AAAA ;0 ;0
DDD88AAAA >0 >0
D8AD8AD8A ;0 >@
D8AD8AD8A >0 @
D8AC@?>2; 20 ;@
D8AC@?>2; >0 20
888CC@@@@ 20
DEPENDENT
>
DEPT6 DEPENDENTNAME SEX DATE RELATIONSHIP ESSN
; Eohn ;0FEA-F8A S.- ;2>?@CA8D
2 Sarah 1 0;F1EBFD2 DA46H"ER ;2>?@CA8D
> Ro)ert ;;FARF2@ 1A"HER >>>??@@@@
? Diane 1 0?FA5RFD; DA46H"ER DDD88AAAA
@ Eenni(er 1 2>FA3FD0 DA46H"ER D8AC@?>2;
C Si%hah 0;FEA-F8C S.- CCC88????
A a)oo) >;FDE+F8@ S.- ?@>?@>?@>
8 Lisa 1 ;2FE4-FAA DA46H"ER D8AD8AD8A