Sunteți pe pagina 1din 18
UNIVERSITY EXAMINATIONS UNIVERSITEITSEKSAMENS. UNISA lien INF3707 MayiJune 2014 DATABASE DESIGN AND IMPLEMENTATION, Duration 2 Hous 100 Marks EXAMINERS FIRST. MR B CHIPANGURA SECOND MR P MACHAKA EXTERNAL DR AG VAN DER VYVER Closed book examination ‘This examination question paper remains the property of the University of South Africa and may not be removed from the examimation venue This paper consists of 9 pages plus an Annexure with 9 pages ‘This examination paper remains the property of the University of South Africa and may not be removed from the examination room INSTRUCTIONS/INSTRUKSIES. 1 All rough work must be done in the answer book 2 The marks for each question mn section B are given in brackets next to the question 3. Please answer the questions in order If you want to do a question later, leave a blank space 4 Study the tables and data in Annexure A GOOD LUCK"! [Turn over] INF3707 June 2014 Section A: 20 marks mns — two (2) mark per question. Choose the correct answer. Write down the question number and the letter of the correct answer (for example 1 E) in your examunation book. Question 1 ‘The Teacher table contains the following columns ID NUMBER(9) Pramary key LAST _NAME VARCHAR2 (25) FIRST NAME VARCHAR? (25) SUBJECT_ID NUMBER (9) ‘Which query should you use to display only the full name of each teacher along with the identification number of the subject each teacher 1s responsible for? a select * from teacher b select last-name, subject_id from teacher © select last_name, farst_name, id from teacher 4. select last_name, first_name, subject-id from teacher Question 2 Indicate which of the following SQL wall display the department numbers and average salaries for departments with a maximum salary that ss greater than 10 000. a select department_id, round(avg(salary)) AVG_SALARY from employees group by department_id having salary > 1000; b select department_id, round(avg(salary)) AVG_SALARY from employees group by department_id where max(salary) > 10000, © select department_id, round(avg(salary)) AVG_SALARY Page |2 [Tum over] INF3707 Sune 2014 from employees group by department _id having AVG_SALARY > 10000; d select department_id, round(avg(salary)) AVG_SALARY from employees group by department_id having max(salary) > 10000, Question 3 Indicate which of the following SQL will correctly display the department that each employee 1s allocated to If the employee 1s not allocated to a department, he/she should also be displayed. a select e.employee_ad, d.department_id from employees e, departments d; b select e.employee id, d department_ad from employees e, departments d where e.department_id = d.department_id; ¢ select e.last_name, d.department_name from employees e RIGHT OUTER JOIN departments d on (d.department_id = e.department_id) ; d select e.last_name, d.department_name from employees e FULL OUTER JOIN departments d on (d.department_id = e.department_ad) ; e select e.last_name, d.department_name from employees e LEFT OUTER JOIN departments 4 on (d department_id = e.department_id) ; Question 4 Evaluate the following SQL statement SQL>SELECT TO_CHAR(1230,'00,999.99') FROM DUAL; What will be the output? 1,230 01,230 1,230.00 01,230.00 aoge Page [3 (Tum over] INF3707, June 2014 Question 5 Examine the structure of the following EMP table EMP table EMPNO NUMBER (3) ENAME VARCHAR2 (25) SALARY NUMBER (10,2) COMM_PCT NUMBER (4,2) You want to generate a report that fulfils the following requirements 1 displays employees’ names and commission amounts 2 excludes employees who do not have a commission 3 displays a zero for employees whose SALARY does not have a value ‘You issue the following SQL statement SQL>SELECT ename, NVL(salary * comm_pct, 0) FROM emp WHERE comm_pet <> NULL; What 1s the outeome? a. It generates an error b_ Itexecutes successfully but displays no result © It executes successfully but displays results that fulfil only requirements 1 and 3 d_ Itexecutes successfully and displays results that fulfil all the requirements Question 6 Which statement 1s true regarding single-row functions? They cannot be nested. They can accept only one argument They act on each row that 1s returned and return only one result per row ‘They act on each row that 1s returned and can return multiple results per row aogr Page | 4 {Tum over] INF3707, June 2014 Question 7 ‘Which statement 1s true regarding a transaction? a Ifa data manipulation statement fails in the middle of a transaction, only that statement 1s rolled back b Ifadata manipulation statement fanls sn the middle of a transaction, the entire transaction 1s rolled back © A transaction 1s not committed when a user exits the session normally without, assuing an explicit COMMIT command dA transaction 1s rolled back when a user exits the session normally without issuing an explicit COMMIT command Question 8 You issue the following SQL command SQL> CREATE TABLE emp (empno NUMBER PRIMARY KEY, ename VARCHAR2(25) NOT NULL, dob TIMESTAMP DEFAULT SYSDATE, bure_date DATE CONSTRAINT h_dt_chk CHECK (hire_date <= SYSDATE)), What will be the outcome? a Itexecutes successfully and creates the table b It generates an error because SYSDATE cannot be used with the CHECK constramt It generates an error because the column size has not been specified for the EMPNO column d_ It generates an error because the default value SYSDATE cannot be used with the TIMESTAMP data type Question 9 Examune the Employee table below EMPNO NOT NULL NUMBER (3) ENAME VARCHAR2 (25) SALARY NUMBER (10,2) comM_PcT NUMBER (4,2) EMPNO 1s the PRIMARY KEY. You issue the following command and create a sequence EMP_SEQ SQL> CREATE SEQUENCE emp_seq, Page |5 (Tum over] INF3707 June 2014 You then insert some rows into the table by using EMP_SEQ to populate the EMPNO column Which statement 1s true regarding the EMP_SEQ sequence? a Itss not affected by any modifications to the EMP table b__Icis automatically dropped when the EMP table 1s dropped ¢ It cannot be used to populate any other column in any table d_ tis automatically dropped when the EMPNO column 1s dropped Question 10 Department table DEPINO ‘NOT _ NULL NUMBER (2) DNAME VARCHAR2 (14) Loc VARCHAR2 (13) Employee table EMPNO NOT NULL NUMBER (4) ENAME VARCHAR2 (10) HIRE_DATE DATE SAL NUMBER(7, 2) DEPTNO NUMBER (2) Examine the structures of the DEPT and EMP tables You have to generate a report that displays all the department names along with the corresponding average salary Which SQL statement will give the required result? a SELECT dname, AVG(sal) FROM emp LEFT OUTER JOIN dept USING(deptno) GROUP BY dname, ; b SELECT dname, AVG(sal) FROM emp JOIN dept USING (deptno) GROUP BY dname, sal; c¢ SELECT dname, sal FROM emp JOIN dept USING(deptno) GROUP BY dname HAVING sal= AVG(sal); d SELECT dname, AVG(sal) FROM emp FULL OUTER JOIN dept USING(deptno) GROUP BY dname; Page |6 [Turn over] INF3707, June 2014 Section B [80 marks] Question 2 [5 marks} Create @ query to display the last name, job ID, and start date for employees with the last names Matos and Taylor Order the query in ascending order by start date (5) Question 3 [5 marks] ‘The Human Resources Department wants to find the length of employment for cach. employee For each employee, display the last name and calculate the number of ‘months between today and the date on which the employee was hired Label the column MOTNTHS_WORKED Order your results by the number of months the employee has been employed Round off the number of months to the closest whole number ©) Question 4 [4 marks] Create a query that displays the employees’ last names and commussion amounts If an employee does not earn commission, show “No Commission” Label the column comM @ Question [4 marks] ‘The Human Resources Department wants to know the difference between the highest paid and the least paid employees Write a query that displays the difference and label the column DIFFERENCE @ Question 6 [6 marks] ‘The Human Resources Department needs a report of employees in Toronto Write a query that displays the last name, job, department number and department name of all the employees who work in Toronto © Question 7 [4 marks] ‘The Human Resources Department needs a report with the following specifications 1 The last name and department ID of all the employees from the employees table, regardless of whether or not they belong to a department 2 The department ID and department name of all the departments from the departments table, regardless of whether or not they have employees who are working in them. Hint use set operators (4) Page |7 (Tum over] INF3707 June 2014 ‘Question 8 [4 marks] ‘The Human Resources Department wants to hide some of the data sn the employees table They want a view that 1s called employees_vu which 1s based on employee number, employee last name and department numbers from the employees table They want the heading for the employee name to be employee Confirm that the view works by displaying the contents of the view 4) Question 9 [5 marks] Provide the SQL that wall prompt the user for the name of the table This SQL will then provide a report that will list the column names, data types, data types lengths and data precision Indicate whether NULLS are allowed for this specific table Provide suitable aliases/headings for the columns Keep in mind that the table name must be in capital letters — use a suitable converter to convert the text that the user enter into capital letters () Question 10 (7 marks] 1 Create a sequence that can be used wath the primary key column of the DEPT table The sequence should start at 200 and have a maximum value of 1000 Increase your sequence by increments of 10 Name the sequence DEPT_ID_SEQ The structure of the DEPT table 1s shown in the table below a) 2 Use the sequence that you created for the ID column to add the department Administration into the DEPT table See table 3 @ Table 3:DEPT table Column Name ‘DEPT_ID DEPT_NAME Key Type Primary ke; ‘Nulls/Unique ‘NOT NULL, NOT NULL ¥K Table FK Column. Data Type Number Length 4 Check Question 11 (15 marks] 1 Provide the SQL that will dynamucally request an employee ID The report will then display the details of all the employees that are managed by the same manager and work in the same department as the employee ID that was read Use a nonpairwise comparison subquery a Page |8 [Turn over] INF3707, June 2014 2 Provide the SQL query that will display only the yobs where there are more than five employees 1n a specific job Use the WITH clause to wnite this query ‘Name the query SUMMARY ) Question 12 [15 marks] 1 Create the employees2 table on the basis of the structure of the employees table Include only employee_id, furst_name, last_name, salary and department_1d @ u Rename the employees2 columns employee_id to ID and department_idtodept_id ) ui Drop the first_name column from the employees? table and confirm your modification by checking the description of the table @ 1 Mark the dept_id column as unused and confirm your modification by checking the descnption of the table ) ¥ Dropall unused columns from the employees? table and confirm your modification by checking the description of the table Q vi Drop the employee? table and query the recycle bin to see if the table 1s present 2) Question 13 [6 marks] Describe what the following regular expressions do 1 REGEXP_REPLACE Q u REGEXP_INSTR Q) 1 REGEXP_SUBSTR Q) The END ° Uni 2014 Page |9 [Tum over] [a9a0 un] po0ses 16.0 mt pours amar | can Acura | | nev sous | | avs, saxon | a1avL saor | mav sunanuivaaa | nave sNouyoot | | save fqe3 wor3 « 3eTeS Y aunxouuy voz ung LOLEANT [19,0 win] " seeAopdue worz y 309Teg | a ° ’ quiN OP INSRRVETA | [A ° 9 qo = UOWEYRV | lo~A 2 : ‘sum TOFRONSTARDS / loa 2 : uns nave | TEEEeer : or aia, arr { je t ea ava aa | | A o —umpeA -HEBMMNTANON | pT = ome are | | sc imma RUN TSVT | | mpeg SRST | | ° - swum OOM seo | rc Co ec ec ae | seekotdue oseq Loz sung “OLEANI [xno wing] mm ' te! nt oS a A REA HABEGT SOL | ANN sau boot sor 06 ggg eonver ——otrsetsisamAvaa “4 pena a 1 vor oor) WONT PEDAL GOEPHTTSIS gaggle oon arte ZL wun on eer OWT REID RFEErOSS yg am a oor uesy our so mmsso—nsrezrOSS gyayl¥ vse wa ‘21 co son coer DONT oN EPEEPESS Lon omy wea sa ® or oo our TwAVIETE —aosr ross ASNT wes cou ‘01 | rl NVI of a youn o a (05 DONT ONES ASPEEHEHS gyn pom =pmay eo | =“ of N | 06 oot omeet NOY NWT RPERLSIS Wag vettsa = aor | | “ : w | 06 ool 0c) ANTON GRAS TE SRPEEESTS ugg 8M apo a : sare osrecisis ona ty a a. a ~AWWN, LSVT | oruNaw wadyavie vn Lava +107 2unp LOLEANT at [sao wang] a sae arNoIoTa A oF amo, AWE KHINTIOS 5 2 x —_OPAMINTOS SaTEIRTOD Beep” sia aord wiuey Saki weg. Gumjoy™ aaa seTzgun0D oseq [Siay be ea spe | wy es repury a dona ! [SWNNOIDaN—arNOIDIa | suofBex worz ~ 399Tes suoyBez oseq ioz sun COLEINT [1000 ung) A A - : z sag ORR a 2 &— BeRRA ORIROWTATVIS oc zrmamea = a Humana, OTTER a o> umema SSTHCOV agar : 1 ° * = sawn UEROREWSET] SOT TTintiea Taya Bayi Ramage” ag Woiessag Giana” Say cea “so suopzeD0T oseq [asia 10} Joma smal aveand| age SO OT WOH AICI” ig on yews xa Kuewan ga! emg x porpaniag HD peg vo eng ae nog aa eaensey ay wamusty ay “SWWN-RAINGOD — GI AHINIOD BeTXAUNOD WoTZ ¥ ZO9TES tz aun LOLEANT (1900 wn] squowjzedep oseq ‘Saas Stou wai 6) OOS as Sea vo work age thé SA 1S ponies 7609 i | | vo * owenug rman, creas aay eupeds opt | sn oun, ais 6186p spe Oe | sa Aesrog may yptasutag ip00S 06005 as wotez L007 | sa ‘euopFED osu ues Winos er66 arg ssOU=N 110Z | sa swat xmas 25190 PAsHPOMIE 102 a - urs x9 o4o-eury 0586 at sama) 0674, o@e 391 yeytngs L102 1 u ‘i ‘om, EOL MI PATS 16066 L a von somo UHH Lt ado VIvVasod Ssmiaav- Lamas “GPAWINAOD “WONTON GLvEs. AED A BUOFIBDCT WOIZ 4 AD9TSS Loz aun ZOLEINI [uaa0 ung] hn a ° 9 QUAN TEPER a ° ° sum TVR . ‘TL -aor ww sor hranee: aaa sqof osea Rn a ES a GY BRN OT HN SY sous oo aannaaxg 06 | eas ow suoMe aN ou | u 8 | suddnys os oe ee or! mn aunseyoing oF ie aunaye ' vonenseuupy squew3zedep wozz » 300TSS loz auny LOLEANI [as0 wing} na a ; ° * sequny OCERSATEVEA : : ot aya, ara E L ara SON, z L ma aIVOrTRVIS Sqwon — OTREXOWRA XWOIST ACT wiry ode, weg mayo, FaeL Ax0387y got oseq Cr pmo anour aot 0 0759)08 Sad asvaDUT A|gU|ENT aD) DI URN A i 00st 008 seiomdomeand — NYWTnd | | o00et 0009 ssomaradey ses anes i 0002 00001 afew NVA | 006 wer punumooo¥ td INAODOV DV | i 00081 oes | | | i | | RUVIVS RWW Rav AVE NI sqof wor3 x 3oeTes loz aun LOLEANT INF3707, June 2014 Select * from job_history ‘AC_ACCOUNT | ISMARST —ACMGR 10 { ope MK REP =m meeciareadicia | BLDECS9 ST.CURK 50 THUN —-ADASST 90 BLDECSS—-SAREP SUDEC99 SAAN 80 | ore ___sbecse _accacnour go | ° UNISA 2014

S-ar putea să vă placă și