MFDB832 Jun 2023 PDF

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

MIDLANDS STATE UNIVERSITY

FACULTY OF BUSINESS SCIENCES

DEPARTMENT OF ACCOUNTING SCIENCES

SQL FOR FINANCIAL DATA

CODE: MFDB832

SESSIONAL EXAMINATIONS

JUNE 2023

DURATION: 3 HOURS

INSTRKTP.NS,T9 CANDIDATES

1. The paper consists of 4 (FOUR) questions.


2. Answer all question in Section A and any two (2)
questions in Section B.
3. Section A carries 30 marks and Each question in Section
B carries 15 marks.
4. Make and state any reasonable assumptions made in
answering the question

Page 1 of 6
SECTION A COMPULSORY

Question 1
a). Explain how a primary key is different to a foreign key. [4]

b). Maxwell wants to add another column 'Age' in the already existing table 'CLIENTS'. He
has written the following statement. However, it has errors. Rewrite the correct statement.
MODIFY TABLE CLIENTS AGE int (1); [3]

c). Table Name: personal_details

Firstname Surname Team Salary Age


Keith Kumbe Dynamos 15 000 18
Dennis Karinga Caps 15 000 20
Ridgemond Huku Chapungu 20 000 24
Wayne Mombe Dynamos 25 000 40
Jack Dziva Highlanders 30 000 26
Peter Hove Dynamos 5 000 28
Chikwekwe t 8 000 30
Patrick Capsi
Nox Bare Highlanders 12 000 35

- i). Write a SQL query which selects firstname, Surname, Team, Salary and Age from the
above table. The query should only display only those who play for Dynamos, Highlanders
and Caps United while earning a salary in the range of "10 000 and 26 000" and also their
age is 35 and below. Sort by Surname in Ascending order. [5]

ii). Display the result set in a table. [5]

d) John wants to update a record where the primary key is Accountnumber="1005- and
"FirstName" is "Peter" but "Firstname" should be "James" in the 'Account* Table. Write an
- SQL statement to correct this record; [3]

e) Explain any 5 differences between the SQL and No-SQL which are necessary to
understand in SQL for financial data. [5]

0 Explain any 5 most commonly used constraints available in SQL [5]

Page 2 of 6
SECTION B — ANSWER ANY 2 QUESTIONS
Question 2

a). (i) Explain the difference between INSERT and INSERT IGNORE [2]

(ii)Use tables as examples, explain the difference between Left Join and Right Join [4]

b). In a School, the students are allocated to programmes. A database named 'School' is
created. One table in this database is: STUDENT with StudentId, StudentName as columns
and StudentId as the primary key. Write another suitable table you could expect to see in the
— School' database, with 3 suitable columns identifying Primary key, Foreign key, data types
and their lengths in the table that you expect. [4]

c). Given below is the 'Department' table:

DEPCODE DEPNAME
101 ADMIN
102 RECEPTION
103 PERSONNEL

SET AUTOCOMMIT = 0;

UPDATE DEPARTMENT SET DEPNAME = 'NEW OFFICE' WHERE DEPNAME =


`ADMIN';

INSERT INTO DEPARTMENT VALUES (105, 'IT');

UPDATE DEPARTMENT SET DEPNAME = `FRONTOFFICE'

- - WHERE DEPNAME = 'PERSONNEL%

COMMIT;

DELETE FROM DEPARTMENT WHERE DEPNAME = 'FRONT OFFICE";

ROLLBACK;

SELECT * FROM DEPARTMENT;

What will be the output of the above given. SELECT statement? [5]

Page 3 of 6
Question 3

a). Name 2 MySQL data types and explain how they are of importance in MySQL. [2]

b). Table Name: account details

Account Firstname Surname Branch Gender


100 Mary Moyo Chegutu Male
101 Jean Beta Masvingo Male
102 Edgar Nick Gweru Male
103 Francis Nhau Chegutu Female
104 Winnet King Mutare Female
105 Cain Nhema Chegutu Female
106 Abel •Kanga Gweru Female
107 Joseph Tende Bulawayo Female

Table Name: Loan

Loanid Account Salary Loan


1 103 6000 50 000
2 100 4000 80 000
3 107 3500 75 000
4 102 2000 60 000
5 105 3000 95 000
6 104 4500 40 000
7 101 7000 120 000

Write the following SQL statements including the result set in a table from the 2 tables above

i) Customers who took loans from Gweru and Chegutu branch while the loan
amount is 50 000 and above. The query should have the following fields: account,
firstname, surname, branch, loan amount [4]
ii) The Company wants to issue loans to customers who earn .a salary which meets
their criteria. List all Customers who earn at least a salary of 4000 [2]

Page 4 of 6
iii) Left join query joining the 2 records above and listing all records sorting by
Account in Ascending Order. The account details table as the left table [3]
iv) The total number of female customers who live in Chegutu [2]
v) The company wants a list of customers who were issued loans in the following
range "50 000 and 100 000". The query should have the following fields: account,
firstname, surname, branch, salary and Ioan amount [2]

Page 5 of 6
Question 4

a). Given below is the 'Tax' table:

ENO NAME
1 Jack King
2 Bismarck Junior

SET AUTOCOMMIT = 0;

INSERT INTO Tax VALUES(5,'Connie') ; COMMIT;

UPDATE Tax SET NAME ='Commando' WHERE Eno= 5; SAVEPOINT A;

INSERT INTO Tax VALUES(6,'Richard') ; SAVEPOINT B;

INSERT INTO Tax VALUES(7,'Rajyalakshmi') ; SAVEPOINT C;

INSERT INTO Tax VALUES(9,'Finance') ; SAVEPOINT E;

INSERT INTO Tax VALUES(8,'Model') ; SAVEPOINT D;

ROLLBACK TO C;

What will be the output of the following SQL query now ordering in Ascending Order by
ENO?

SELECT * FROM Tax; [5]

b). With the aid of examples, explain and illustrates the syntax of the following clause:

(i) REPLACE [2]

(ii) HAVING [2]

(iii) COUNT [2]

(iv) ROLLUP [2]

(v) CROSS JOIN [2]

**END OF EXAMINATION**

Page 6 of 6

You might also like