SQL
SQL
Question 02: You will create between 6 to 10 tables (Not more than 10 tables) that
will store information you wish to keep track of.
I create the 8 tables related to the financial database in which 6 tables are dimension table and 2
tables are fact or transactional tables.
Question 03: Provide details about the project, explaining what sort of information
in a database explaining the use of each table and why you selected this project. –
(10 marks).
The project appears to be related to a financial database, and it consists of several tables and
associated operations. Here's a summary of the project: The project involves creating a database
called "Finance." It seems to be designed to manage financial data, possibly for a bank or
financial institution.
Database Tables:
Customers: This table stores customer information, including their first name, last name,
address, and phone number.
Accounts: It contains details about the accounts associated with customers, such as the
account type and balance.
Currency: This table appears to hold currency-related data, such as currency codes and
names.
TransactionTypes: Stores types of transactions, which could be used to categorize
financial transactions.
BankTransactions: A fact table for bank transactions, including customer, account,
transaction type, date, and amount.
InvestmentTransactions: Similar to BankTransactions but for investment-related
transactions. It is also a fact table.
Investments: Contains data about investments, including type, purchase date, amount,
and current value.
CreditScores: Records credit scores and ratings for customers.
Question 04: Most of the tables would be dimension (lookup) tables. You must have
at least one or two fact tables (transactional tables).
I create the two fact or transactional tables BankTransactions and IvestnebtTransaction and the
queries are given below:
Question 05: Populate the table with 10 rows for dimension tables, 20 – 50 rows for
transactional tables.
I insert the 10 rows and 20 rows in the tables and the code is given in the file. Only shows
the customer dimension table and the InvestmentTranscations table and the rest of query
are given in the sql file .
Question 06: Generate the ERD diagram and paste it in a word document.
Accounts * FK_A ccounts_Inv estmentTransactions InvestmentTransactions *
AccountID InvestmentTransactionID
CustomerID CustomerID
AccountType TransactionTypeID
Amount
CreditScores * TransactionTypes *
CreditScoreID
FK_C ustomers_C reditScores TransactionTypeID
CustomerID FK_C ustomers_A ccounts FK_Inv estmentTransactions_Inv estments
TypeName
CreditScore
CreditRating Customers *
CustomerID Investments *
FirstName CustomerID
FK_C reditScores_C urrency FK_TransactionTy pes_BankTransactions
LastName InvestmentType
Address InvestmentAmount
CurrencyName AccountID
TransactionTypeID
TransactionDate
Amount
Question 07: Create three queries and convert them into views and explain why you
think would be useful to the user.
I will create three sample SQL queries and convert them into views for your financial database
system. There are several views defined, such as "CustomerAccountBalances," which provides a
combined view of customer and account data. "InvestmentPerformance" seems to be related to
investments. "RecentBankTransactions" provides a view of recent bank transactions.
This view provides users with an overview of their investments, including the type of
investment, purchase date, current value, and the calculated Return on Investment (ROI)
percentage. It helps users assess the performance of their investments.
This view displays recent bank transactions for the past 30 days, providing users with insight into
their recent financial activities
Question 08: Create an audit table for one of the lookup tables and demonstrate
data saved to that audit table when data in the original table is inserted, modified,
or deleted. Include an additional column in the audit table that will have a datetime
field when the data was changed in the original table.
go
-- Create a trigger to log changes in Currency to CurrencyAudit
CREATE TRIGGER CurrencyAuditTrigger
ON Currency
AFTER INSERT, UPDATE, DELETE
AS
BEGIN
DECLARE @ChangeType VARCHAR(10);
Question 09: Demonstrate a use of the two stored procedures for your database. Create
and drop script for two stored procedures.
go
-- Create the GetCustomersByLastName stored procedure
CREATE PROCEDURE GetCustomersByLastName
@LastName VARCHAR(50)
AS
BEGIN
SELECT *
FROM Customers
WHERE LastName = @LastName;
END;
go
Question 10: Demonstrate the use of two cursors for your database. Create and drop script
for two cursors.
Audit Table and Trigger: The "CurrencyAudit" table is created to log changes in the "Currency"
table. A trigger, "CurrencyAuditTrigger," is defined to capture and log changes in the currency
table.
Project Rationale: The project appears to be aimed at managing financial data, including
customer information, accounts, transactions, investments, and currency data. It includes views
for data retrieval and an audit mechanism for tracking changes to currency data. Stored
procedures and cursors may be used for specific data manipulation and reporting tasks.
The purpose of this project might be to build a financial database system for a bank or financial
institution, allowing them to manage customer data, financial accounts, transactions,
investments, and currency information efficiently. The database's schema and associated objects
are designed to support data management, analysis, and reporting in a financial context.