Suppose that, instead of allowing negative account balances, the bank treats the
ID: 3732119 • Letter: S
Question
Suppose that, instead of allowing negative account balances, the bank treats the overdrafts by zeroing the balance of the accounts and creating a loan for the amount of the overdraft.
This loan receives a loan number identical to the account number that the overdraft has had.
In this example, the condition to execute the Trigger is an update of the account relationship that results in a negative balance value.
Suppose that Hayes withdrew a certain amount of money from an account that resulted in the account balance being negative. t denotes the tuple of the account with a negative balance value. Determine and write:
The actions to follow.
The Trigger (the same must remain on the server under your account, with the name overdraff)
Explanation / Answer
A trigger is actually a statement that is executed automatically by a particular system as a side effect of a modification to the database.
For the design of the trigger and the actions which must be taken for the above problem are:
- First of all the conditions under the trigger to be executed must be specified.
- Next is to specify the actions which should be taken when the trigger executes.
The condition for the execution of the trigger is an update to account relation which must result in negative balance value.
Trigger Creation example:
create trigger overdraft after update on account with reference to new row as Nrow
for each row
when Nrow.balance < 0
begin atomic
insert into borrower account
(select cust-name, accnt-num
from depositor
where Nrow.accnt-num = depositor.accnt-num);
insert into loan values
(N.row.accnt-num, Nrow, branch-name, -Nrow.balance);
update account set balance = 0
where accnt.accnt-num = N.row.accnt-num
end
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.