database application

64 downloads 1553 Views 146KB Size Report
(g) Write SQL code that will calculate the age of student Michael Connoly and display the output using the column heading text “Student Age”. [3 Marks].
Bsc(Hons) Software Engineering BSc (Hons.) Business Information Systems Cohort: BSE/11/FT, BSE/10B/FT, BIS/10A/FT & BIS/11/FT

Resit Examinations for 2012 - 2013 / Semester2 MODULE: DATABASE APPLICATION MODULE CODE: DBT1102C Duration: 2 Hours 30 Minutes

Instructions to Candidates: 1.

CANDIDATE SHOULD ATTEMPT ALL QUESTIONS

2.

All questions carry equal marks

3.

Total Marks = 100

This question paper contains 4 questions and 8 pages.

Page 1 of 8 Database Application (DBT1102C)

SITE/DA 2012-2013 S2

Question 1 (25 Marks) This question refers to the database Schema given in Appendix.

(a) Write the SQL code that will create ALL the tables as given in the appendix. Your answer should not contain the primary key and foreign key constraint declaration. The data type for each attribute should be as specified in the Appendix. Assume that the tables will be associated with the dbo schema. The tables must be created on the Primary Filegroup and the table will NOT make use of the IDENTITY feature to automatically increment the Primary Key value. [8 Marks] (b) Assuming that all the tables have been created as given in the relational schema in the Appendix, write SQL code to make the following changes in the structure of the tables. Explain in which order the following constraint will have to be created so that the SQL Script does not generate any errors. (i) Make the S_ID the Primary Key and the F_ID as the Foreign Key in the STUDENT table. [4 Marks] (ii) Create a constraint in the STUDENT table for the S_CLASS column, so that it will only accept the following values: FR, JR, SR AND SO [2 Marks] (iii) Make the F_ID the Primary Key and the LOC_ID as the Foreign Key in the FACULTY table. [4 Marks] (iv) Create a constraint in the FACULTY table for the F_RANK column, so that it will only accept the following values: ASSO, ASST, FULL and INST [3 Marks] (v) Make the LOC_ID the Primary Key of the LOCATION table. [2 Marks] (vi) Create a constraint for the F_PIN in FACULTY table, so that no two person will have the same PIN number. [2 Marks]

Page 2 of 8 Database Application (DBT1102C)

SITE/DA 2012-2013 S2

Question 2 (25 Marks) This question refers to the database Schema given in Appendix II. (a) Identify all foreign keys in the STUDENT table in which the S_ID value is 1. Then, write the commands to insert the records in which these foreign keys are primary keys, using the data values given in APPENDIX. If these new records contain any foreign keys as well, write the commands to insert the records in which these foreign keys are primary keys also. Be sure to write the commands in the correct order so that you insert each primary key value before you insert the record that references the primary key value as a foreign key. [4 Marks] (b) Write SQL code which will modify the student class value of the student Amanda Mobley to SR. [2 Marks] (c) Retrieve the S_CLASS field values for all rows in the Student table and suppress duplicate output. Sort the values in alphabetical order. [2 Marks] (d) Retrieve the S_FIRST, S_LAST, and S_MI field values for every student who does not have a value for S_MI. [2 Marks] (e) Retrieve the S_FIRST, S_LAST, and S_DOB field values for all students whose S_CLASS value is either ‘JR’ or ‘SR’. [2 Marks] (f) Retrieve the S_FIRST, S_LAST and S_DOB field values for all students who were born during 1985. [3 Marks] (g) Write SQL code that will calculate the age of student Michael Connoly and display the output using the column heading text “Student Age”. [3 Marks] (h) List the building code and room number of all locations that have the same capacity as CR 103. [3 Marks] (i) List the bldg_code and the sum of capacity by the bldg_code for all location whose sum of the capacity is greater than 100. [4 Marks]

Page 3 of 8 Database Application (DBT1102C)

SITE/DA 2012-2013 S2

Question 3 (25 Marks) (a) The GROUP BY clause specifies the groups into which the output rows of a table must be placed. The following is the syntax of the GROUP BY clause. [ GROUP BY [ ALL ] group_by_expression [ ,...n ] [ WITH { CUBE | ROLLUP } ]] Given the following table:

Explain the output generated by the following SQL statement: (i)

SELECT Type, Store, SUM(Number) as Number FROM Pets GROUP BY type, store WITH ROLLUP

[4 Marks] (ii)

SELECT Type, Store, SUM(Number) as Number FROM Pets GROUP BY type, store WITH CUBE [4 Marks]

(b) What is a view? [2 Marks] (c) Can we use a view to insert or update a record into a table? Do we have any limitation to perform the above command? [3 Marks]

Page 4 of 8 Database Application (DBT1102C)

SITE/DA 2012-2013 S2

(d) The syntax to create a view is given below: CREATE VIEW [database_name.][schema_name.]view_name WITH {ENCRYPTION | SCHEMABINDING} AS SELECT_statement Explain the purpose of the Encryption and Schemabinding keyword in the above syntax. [6 Marks] (e) What are joins? Describe the different types of join which is possible in SQL Server 2005 [4 Marks] (f) Explain the purpose of the EXCEPT operator. [2 Marks]

Page 5 of 8 Database Application (DBT1102C)

SITE/DA 2012-2013 S2

Question 4 (25 Marks) (a) State whether the following statements are TRUE or FALSE. (i) When creating a project in Visual Basic you should always begin by writing the Basic code. (ii) When you are designing the user interface and writing code you are in run time. (iii) After you have added a command button to a form you can change what is displayed on the form (inside the button) by changing the Caption property (iv) Remark statements are not executable code. (v) If a project runs without halting, you can be assured that the code was written without error. (vi) You write Visual Basic code statements during Design Time. [6 Marks] (b) Write statements to clear a text box named txtPlace and then reset the insertion point to that text box. [2 Marks] (c) Explain the statement lblStart.Caption = Format(StartTime, "hh:mm:ss")

, where lblstart is the name of a label. [2 Marks] (d) Write short notes on the following Visual basic errors: (i) Syntax errors (ii) Run-time errors (iii) Logic errors. [6 Marks] (e) Write an If statement that assigns the value of 10 to the variable intSum if intNum is greater than 19. Otherwise, the If statement will assign the value of 5 to intSum. [3 Marks] (f) A Visual Basic application cannot directly interact with a database. There are two intermediate components between the application and the database. Using an appropriate diagram explain in details the two components. [6 Marks]

Page 6 of 8 Database Application (DBT1102C)

SITE/DA 2012-2013 S2

APPENDIX The Student Registration System (SRS) Table Descriptions DESCRIBE Faculty

Select * from faculty;

DESCRIBE Location

Select * from location;

Page 7 of 8 Database Application (DBT1102C)

SITE/DA 2012-2013 S2

Describe Student;

Select * from Student;

***END OF PAPER***

Page 8 of 8 Database Application (DBT1102C)

SITE/DA 2012-2013 S2