Extra Marks Flashcards

1
Q

Given the following database Schema answer the questions that
follow:
STUDENT(cisNum, name, gender,age )
BOOK(bookId, title)
BORROW (cisNum, bookId, dateBorrowd, dueDate)

a) Write SQL statement snippets that would enforce entity integrity and referential integrity for all three tables.

A

Entity Integrity:
ALTER TABLE STUDENT
ADD PRIMARY KEY (cisNum);

ALTER TABLE BOOK
ADD PRIMARY KEY (bookId);

ALTER TABLE BORROW
ADD PRIMARY KEY (cisNum, bookId);

Referential Integrity:
ALTER TABLE BORROW
ADD FOREIGN KEY (cisNum) REFERENCES STUDENT(cisNum);

ALTER TABLE BORROW
ADD FOREIGN KEY (bookId) REFERENCES BOOK(bookId);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Given the following database Schema answer the questions that
follow:
STUDENT(cisNum, name, gender,age )
BOOK(bookId, title)
BORROW (cisNum, bookId, dateBorrowd, dueDate)

b) Explain how entity integrity may prevent the insertion of a row of data into a table.

A

Entity integrity ensures unique primary keys, rejecting insertion attempts with duplicate primary key values, preserving uniqueness.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Given the following database Schema answer the questions that
follow:
STUDENT(cisNum, name, gender,age )
BOOK(bookId, title)
BORROW (cisNum, bookId, dateBorrowd, dueDate)

c) Explain how referential integrity may prevent the insertion of a row of data into a table.

A

Referential integrity ensures foreign key values match primary key values in referenced tables, rejecting insertions without matching keys.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Explain what this procedure does.
CREATE OR REPLACE PROCEDURE ladystudents
As
CURSOR abc IS select * from student where gender
= ‘F’ ;
Females abc%ROWTYPE;
BEGIN
OPEN abc
LOOP
FETCH abc into Females;
DBMS_OUTPUT.PUT_LINE(Females.TutorName);
EXIT WHEN abc%NOTFOUND;
END LOOP;
CLOSE abc;
END;

A

The procedure fetches and outputs the TutorName of female students using a cursor, iterating through the result set and printing the TutorName for each row.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Explain what this trigger does.
CREATE OR REPLACE PROCEDURE upadareMaleAges
As
CURSOR abc IS select * from student where gender =
‘M’ ;
Females abc%ROWTYPE;
BEGIN
OPEN abc
LOOP
FETCH abc into Males;
Update student set age = Males.age + 2 where cis
= Males.cis;
EXIT WHEN abc%NOTFOUND;
END LOOP;
CLOSE abc;
END;

A

The procedure updates the ages of male students by adding 2 to their current age in the STUDENT table.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Analyse the logical tables below and answer the questions that follow.
Client(client_Id, name, address,gender, age)
Account(acc_no, acc_name, balance)
Withdrawal (acc_no, client_Id,amt_withdrawn, date)
Note: Primary keys are underlined and the primary key for withdrawal
table is foreign
a) Name the strong entities featured on the above logical tables

A

Strong entities are Client and Account.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Write SQL statements to do the following
i. write an SQL to create the table withdrawal

A

CREATE TABLE Withdrawal (
acc_no INT,
client_Id INT,
amt_withdrawn DECIMAL(10, 2),
date DATE,
PRIMARY KEY (acc_no),
FOREIGN KEY (client_Id) REFERENCES Client(client_Id)
);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Write SQL statements to do the following
SQL Statement to List Clients who Made Withdrawals on 23 September 2020:

A

SELECT * FROM Client
WHERE client_Id IN (
SELECT client_Id FROM Withdrawal
WHERE date = ‘2020-09-23’
);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Write SQL statements to do the following
SQL Statement to Give Total Number of Clients:

A

SELECT COUNT(*) AS TotalClients FROM Client;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Write SQL statements to do the following
SQL Statement to Add City Column to Client Table:

A

ALTER TABLE Client
ADD city VARCHAR(50);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Write SQL statements to do the following
Trigger to Impose Maximum Withdrawal Amount:

A

CREATE OR REPLACE TRIGGER maxWithdrawal
BEFORE INSERT ON Withdrawal
FOR EACH ROW
BEGIN
IF :NEW.amt_withdrawn > 4000.00 THEN
RAISE_APPLICATION_ERROR(-20000, ‘Maximum withdrawal amount exceeded’);
END IF;
END;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly