Get Instant Help From 5000+ Experts For
question

Writing: Get your essay and assignment written from scratch by PhD expert

Rewriting: Paraphrase or rewrite your friend's essay with similar meaning at reduced cost

Editing:Proofread your work by experts and improve grade at Lowest cost

And Improve Your Grades
myassignmenthelp.com
loader
Phone no. Missing!

Enter phone no. to receive critical updates and urgent messages !

Attach file

Error goes here

Files Missing!

Please upload all relevant files for quick & complete assistance.

Guaranteed Higher Grade!
Free Quote
wave

Generate seven tables and populate them usingthe script provided in the assignment folder.You can optionally create and populate them by yourself, but make sure there is strong alignment between the tables created and rows populated by the script andthose by you. In particular, lookcare fully at how the primary key of the table forrepayment(T_Repayment)is automatically generated,and how row sare inserted toit.


Procedure for Loan Repayment 
At Spock Bank, loan repayments are made purely online by transferring fund from another account – typically a savings account-- to the loan account. The customers normally use the bank’s app or webpage and specify from which account they would want to make the repayment,andtowardswhichloan his payment should count.This action of the customer will effectively callastored procedureas:

Loan Repayment Procedure

  • Procedure Implementation

DELIMITER $$

CREATE DEFINER=`root`@`localhost` PROCEDURE `repay_loan`(IN `from_BSB` VARCHAR(10), IN `from_accountNo` VARCHAR(10), IN `to_loan` VARCHAR(10), IN `amount` DECIMAL(8))

BEGIN

declarehasAccount INTEGER;

declareisLoanMatch INTEGER;

declare balance INTEGER;

declareownsAccount INTEGER;

select count(*) into hasAccount from t_account where `BSB` = from_BSB and `AccountNo`=from_accountNo;

select count(*) into ownsAccount from t_own where Customer_ID in (select a.Customer_ID from t_own a, t_loan b where a.Account_BSB = b.Loan_AccountBSB and a.Account_No = b.Loan_AcctNo and b.LoanID = to_loan);

IF (hasAccount>0) THEN

selectAccountBal into balance from t_account where BSB = from_BSB and

AccountNo=from_accountNo;

if(ownsAccount>0) THEN

if (balance>=amount) then

INSERT into t_repayment (RepaymentAmount, Repayment_LoanID, RepaymentDate)

          VALUES(amount,to_loan, now());

       SELECT 'Loan Repayment Succeeded';

       ELSE

       SELECT 'Insufficient funds to complete this transaction';

       End IF;

       ELSE

        SELECT 'Paying someones else loan';

        END IF;

       ELSE

       SELECT 'Account does not exist';

   END IF;

END$$

DELIMITER ;

  • Procedure Testing
  • Successful Repayment

MariaDB [spockbank]> call repay_loan('BSB3','Acct4','L1',1);

+--------------------------+

| Loan Repayment Succeeded |

+--------------------------+

| Loan Repayment Succeeded |

+--------------------------+

1 row in set (0.06 sec)

  • Unsuccessful Repayment - attempt by a third party

MariaDB [spockbank]> call repay_loan('BSB1','Acct5','L1',1);

+--------------------------+

| Loan Repayment Failed. Account owner not found |

+--------------------------+

| Loan Repayment Failed. Account owner not found |

+--------------------------+

1 row in set (0.06 sec)

  • Unsuccessful Repayment – insufficient funds

MariaDB [spockbank]> call repay_loan('BSB3','Acct4','L1',10000000);

+-------------------------------------------------+

| Insufficient funds to complete this transaction |

+-------------------------------------------------+

| Insufficient funds to complete this transaction |

+-------------------------------------------------+

TASK 3 DATABASE TRIGGER

  • Rationale behind the type of trigger used

The trigger is created to operate before insertion and stop saving of the loan when a condition is not met.

  • How the trigger is tested (methodology)

The trigger is tested by trying to perform a transaction on the t_loan table on which the trigger is created for. Any intended insertion will invoke the trigger whoch

  • Implementation of the trigger

The trigger is implemented on the t_loan table where any attempt to insert will invoke the trigger. When invoked, the trigger will check all the rules defined and stop insertion if any of the rule condition fails.

  • Code for implementing the trigger

CREATE TRIGGER `check_before_insert_loan` BEFORE INSERT ON `t_loan`

 FOR EACH ROW BEGIN

    DECLARE done INT DEFAULT FALSE;

    DECLARE id VARCHAR(10);

    DECLARE LoanTypeVARCHAR(10);

    DECLARE total INT;

    DECLARE allLoans INT;

    DECLARE personal INT;

    DECLARE homeLoan INT;

    DECLARE amount INT;

    DECLARE OK_INSERT INT DEFAULT 1;

    DECLARE LastLoanIDVARCHAR(10);

    DECLARE cur CURSOR FOR SELECT Customer_ID FROM t_own where Account_BSB = NEW.Loan_AccountBSB and Account_No = New.Loan_AcctNo;

    DECLARE CONTINUE HANDLER FOR NOT FOUND

   SET done = TRUE;

OPEN cur;

SELECT FOUND_ROWS() INTO total;

ins_loop: LOOP

   FETCH cur INTO id;

Stored Procedure Script

          SELECT COUNT(*) into allLoans FROM t_loan a, t_own b WHERE a.Loan_AccountBSB = b.Account_BSB and a.Loan_AcctNo=b.Account_No                     and  b.Customer_ID = id;

IF(allLoans>8) THEN

   SIGNAL SQLSTATE  '45000';

        END IF;

        SELECT COUNT(*) into homeLoan FROM t_loan a, t_own b WHERE a.Loan_AccountBSB = b.Account_BSB and a.Loan_AcctNo=b.Account_No and  b.Customer_ID = id and a.Loan_Type='LT1';

IF(homeLoan>=3 and New.Loan_Type='LT1') THEN

   SIGNAL SQLSTATE  '45000';

        END IF;

         SELECT COUNT(*) into personal FROM t_loan a, t_own b WHERE a.Loan_AccountBSB = b.Account_BSB and a.Loan_AcctNo=b.Account_No                     and  b.Customer_ID = id and a.Loan_Type='LT3';

IF(personal>=1 and New.Loan_Type='LT3') THEN

          SIGNAL SQLSTATE  '45000';

        END IF;

        SELECT SUM(LoanAmount) into total FROM t_loan a, t_own b WHERE a.Loan_AccountBSB = b.Account_BSB and                                                  a.Loan_AcctNo=b.Account_No and  b.Customer_ID = id;

IF((total+NEW.LoanAmount) > 10000000) THEN

   SIGNAL SQLSTATE  '45000';

        END IF;

   IF done THEN

          LEAVE ins_loop;

   END IF;

END LOOP;

CLOSE cur;

END

  • Script for testing the trigger (and test results)
  1. User has more than five personal loans and insertion fails.

MariaDB [spockbank]> INSERT INTO `t_loan` (`LoanID`, `LoanRate`, `LoanAmount`, `Loan_Type`, `Loan_AccountBSB`, `Loan_AcctNo`, `offsetAcct_BSB`, `offsetAcct_No`) VALUES ('L14', '0.02', '1100', 'LT2', 'BSB3', 'Acct2', 'BSB1', 'Acct6');

ERROR 1644 (45000): Unhandled user-defined exception condition

MariaDB [spockbank]>

  1. Maximum 8 loans per person

MariaDB [spockbank]> INSERT INTO `t_loan` (`LoanID`, `LoanRate`, `LoanAmount`, `Loan_Type`, `Loan_AccountBSB`, `Loan_AcctNo`, `offsetAcct_BSB`, `offsetAcct_No`) VALUES ('L14', '0.02', '16200', 'LT2', 'BSB2', 'Acct2', 'BSB1', 'Acct6');

ERROR 1644 (45000): Unhandled user-defined exception condition

MariaDB [spockbank]>

  1. More than one personal loan

MariaDB [spockbank]> INSERT INTO `t_loan` (`LoanID`, `LoanRate`, `LoanAmount`, `Loan_Type`, `Loan_AccountBSB`, `Loan_AcctNo`, `offsetAcct_BSB`, `offsetAcct_No`) VALUES ('L6', '0.01', '5000', 'LT3', 'BSB3', 'Acct4', 'BSB1', 'Acct6');

ERROR 1644 (45000): Unhandled user-defined exception condition

MariaDB [spockbank]>

  1. Total amount exceeds 10,000,000

MariaDB [spockbank]> INSERT INTO `t_loan` (`LoanID`, `LoanRate`, `LoanAmount`, `Loan_Type`, `Loan_AccountBSB`, `Loan_AcctNo`, `offsetAcct_BSB`, `offsetAcct_No`) VALUES ('L5', '0.03', '11000000', 'LT1', 'BSB3', 'Acct3', 'BSB1', 'Acct6');

ERROR 1644 (45000): Unhandled user-defined exception condition

MariaDB [spockbank]>

  • One person more than 3 home loans

MariaDB [spockbank]> INSERT INTO `t_loan` (`LoanID`, `LoanRate`, `LoanAmount`, `Loan_Type`, `Loan_AccountBSB`, `Loan_AcctNo`, `offsetAcct_BSB`, `offsetAcct_No`) VALUES ('L6', '0.03', '670', 'LT1', 'BSB3', 'Acct3', 'BSB1', 'Acct6');

ERROR 1644 (45000): Unhandled user-defined exception condition

MariaDB [spockbank]>

TASK 4 INTEREST CALCULATION

  • Issues with Relational Schema

The schema cannot be able to implement the proposed functionality because there is no key to link a loan with an offset account. It would be impossible to determine the account to use to calculate the interest based on offset account.

  • Suggested changes to the Relational Schema

In order to support the specified operation, a foreign key should be introduced into the table to help link the loan with the offset account. This will help in identifying the offset account associated with the loan.

  • Implementation of the suggested changes

To implement this functionality, the table t_loan needs to be altered and two columns added. These columns will allow to identify an offset account associated with the loan.

  • SQL Code

Examples of the Procedure in Action

ALTER TABLE `t_loan` ADD `offsetAcct_BSB` VARCHAR(10) NOT NULL AFTER `Loan_AcctNo`, ADD `offsetAcct_No` VARCHAR(10) NOT NULL AFTER `offsetAcct_BSB`;

  • Errors/ Warnings

No errors or warning thrown by the operation.

  • Interest Calculation Procedure

DELIMITER $$

CREATE DEFINER=`root`@`localhost` PROCEDURE `calculate_loan`(IN `pay_date` DATE)

BEGIN

declare done int default false;

declareloansid varchar(10);

declare rate float;

declare paid float;

declaretotalAmt float;

declareremainingAmt float;

declarenumberOfDays float;

declare interest float;

declare found float;

declareoffsetAmt float;

declaretobePaid float default 0;

declareoffsetBSB varchar(10);

declareoffsetAccountNo varchar(10);

declareloanAccountNo varchar(10);

declareloanAccountBSB varchar(10);

 DECLARE cur CURSOR FOR SELECT LoanID FROM t_loan;

    DECLARE CONTINUE HANDLER FOR NOT FOUND

    SET done =true;

    OPEN cur;

select FOUND_ROWS() into found;

ins_loop: LOOP

   FETCH cur INTO loansid;

selectoffsetAcct_BSB into offsetBSB from t_loan where LoanID = loansid;

selectoffsetAcct_No into offsetAccountNo from t_loan where LoanID = loansid;

selectLoan_AccountBSB into loanAccountBSB from t_loan where LoanID = loansid;

selectLoan_AcctNo into loanAccountNo from t_loan where LoanID = loansid;

selectLoanRate into rate from t_loan where LoanID = loansid;

   select sum(RepaymentAmount) into paid from t_repayment where Repayment_LoanID = loansid;

selectLoanAmount into totalAmt from t_loan where LoanID = loansid;

selectAccountBal into offsetAmt from t_account where AccountNo = offsetAccountNo and BSB = offsetBSB;

select DAY(LAST_DAY(CAST(pay_date as DATE))) into numberOfDays;

setremainingAmt = (totalAmt-paid-offsetAmt);

set interest = (remainingAmt*rate*numberOfDays);

settobePaid = (remainingAmt + interest);

updatet_account set AccountBal = tobePaid where AccountNo=loanAccountNo and BSB =loanAccountBSB;

   IF done THEN

         LEAVE ins_loop;

   END IF;

END LOOP;

CLOSE cur;

SELECT a.* from t_account a, t_loan b where b.Loan_AccountBSB = a.BSB and b.Loan_AcctNo = a.AccountNo and a.AccountBal>0;

END$$

DELIMITER ;

(e) Testing the procedure for monthly interest calculation

       (i) On March 25, 2018

MariaDB [spockbank]> SET @p0='2018-03-25 00:00:00.000000'; CALL `calculate_loan`(@p0);

BSB2

Acct2

30345

AT3

BSB3

Acct4

6982

AT3

On May 25, 2018

MariaDB [spockbank]> SET @p0='2018-05-25 00:00:00.000000'; CALL `calculate_loan`(@p0);

BSB2

Acct2

28243

AT3

BSB3

Acct4

6933

AT3

On August 25, 2018

MariaDB [spockbank]> SET @p0='2018-08-25 00:00:00.000000'; CALL `calculate_loan`(@p0);

BSB2

Acct2

23422

AT3

BSB3

Acct4

6523

AT3

TASK 5

  1. Transactions

A transaction is a complete piece of processing performed by a database which is ACID.ACID is an acronym that stands for  atomicity, consistency, isolation and durability(“Atomicity,” n.d.);

  1. b) Schedule, Transaction and differences;

A schedule determines how transactions will be carried within a database system. It is a sequence of instructions to be carried out by the database management system in predetermined times. A schedule differs from a transaction in that it involves a group of transactions and other non-transaction queries to be carried within a database system(Fowler, 2002).

  1. c) Conflict serializable schedule

A conflict serializable schedule is a schedule that allows the database management system to swap conflicting operations with non-conflicting operations. Conflict serializable schedule belong to different transactions but operate on the same data item.

Conflict serializable schedule ensures database consistency by including locking mechanism and recoverability of the database during the operation. They also ensure each operation abides by data consistency rules defined.

  1. d) conflict-serializable schedules and states.

Theconflict-serializable schedules do not leave with the same value for corresponding data items because the order of the operations may change and therefore different transactions may have taken place before or after each schedule.

  1. e) View serializability and its weaknesses

View serializability reads data after a transaction has completed as opposed to conflict serializabuility that reads data before transaction. View serializability is weak because it reads data after commit which may already have been manipulated hence it has no way of preventing conflicts compared to conflict serializability.

References

Atomicity. (n.d.). Retrieved September 23, 2018.

Fowler, M. (2002). Patterns of Enterprise Application Architecture. Source (Vol. 48).

Cite This Work

To export a reference to this article please select a referencing stye below:

My Assignment Help. (2021). Essay: Loan Repayment Procedure & Trigger For Loan Validation In Spock Bank DB System.. Retrieved from https://myassignmenthelp.com/free-samples/isys224-database-systems/in-non-transaction.html.

"Essay: Loan Repayment Procedure & Trigger For Loan Validation In Spock Bank DB System.." My Assignment Help, 2021, https://myassignmenthelp.com/free-samples/isys224-database-systems/in-non-transaction.html.

My Assignment Help (2021) Essay: Loan Repayment Procedure & Trigger For Loan Validation In Spock Bank DB System. [Online]. Available from: https://myassignmenthelp.com/free-samples/isys224-database-systems/in-non-transaction.html
[Accessed 24 April 2024].

My Assignment Help. 'Essay: Loan Repayment Procedure & Trigger For Loan Validation In Spock Bank DB System.' (My Assignment Help, 2021) <https://myassignmenthelp.com/free-samples/isys224-database-systems/in-non-transaction.html> accessed 24 April 2024.

My Assignment Help. Essay: Loan Repayment Procedure & Trigger For Loan Validation In Spock Bank DB System. [Internet]. My Assignment Help. 2021 [cited 24 April 2024]. Available from: https://myassignmenthelp.com/free-samples/isys224-database-systems/in-non-transaction.html.

Get instant help from 5000+ experts for
question

Writing: Get your essay and assignment written from scratch by PhD expert

Rewriting: Paraphrase or rewrite your friend's essay with similar meaning at reduced cost

Editing: Proofread your work by experts and improve grade at Lowest cost

loader
250 words
Phone no. Missing!

Enter phone no. to receive critical updates and urgent messages !

Attach file

Error goes here

Files Missing!

Please upload all relevant files for quick & complete assistance.

Plagiarism checker
Verify originality of an essay
essay
Generate unique essays in a jiffy
Plagiarism checker
Cite sources with ease
support
Whatsapp
callback
sales
sales chat
Whatsapp
callback
sales chat
close