Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

SQL Commands For Final

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

PHASE 1:

PHASE 2:
Phase 2: Database Initial Study In this phase, teams will focus on the design aspect of the project with an emphasis on
applying key principles and concepts such as data modelling, Entity-relationship (ER) modelling and normalization.

You are required to create designs that meet the requirements of Future Builders Credit Union.

THE DESIGN SHOULD CONTAIN:


5. Conceptual Design (High Level – CROW’s FOOT MODEL (10 marks)

a. Should reflect the following:


i. Entities: Objects/tables
ii. Business rules
iii. Connectivity: Relationship classification/type
iv. Relationship Participation (optional/mandatory)

6. Logical Design – CROW’s FOOT MODEL (10marks) Should reflect the following:
i. Entities: Objects/tables
ii. Attributes: characteristics/fields
iii. Keys: Primary/Foreign
iv. Business rules v. Connectivity: Relationship classification/type vi. Cardinalities (where applicable) vii. Relationship
Participation (optional/mandatory) viii. Associative/Composite/bridge entities (where applicable) ix. Strong & Weak
relationships x. Multivalued attributes using CHEN NOTATION (if applicable)

(Guide)

Phase 3: Data Implementation


In this phase, we created the database using MS ACCESS,
You will populate the tables with sample data and then write SQL statements to answer some relevant questions that may be asked of your database.
THE Database SHOULD CONTAIN

1. Sample Data in all tables (15 marks)


a. Should reflect the following:
i. At least 5 rows EACH
ii. Use a variety of data types
1. At least ONE instance of character/text
2. At least ONE instance of numeric
3. At least ONE instance of Date
4. At least ONE instance of character/text

2. SQL STATEMENTS (25 marks) Use SQL statements which include instances of the following commands and options
a. Create Table
b. Altar Table
c. Insert
d. Select (using Where, Group by, Having and Order by)
e. Update
f. Comparison operators (at least THREE)
g. Logical operators (at least TWO) h. Special Operators (at least THREE)
i. Aggregate functions (at least TWO)

Conceptual Design

Conceptual ERD models the business objects that should exist in a system and the relationships
between them. A conceptual model is developed to present an overall picture of the system by
recognizing the business objects involved. It defines what entities exist, NOT which tables. For
example, One to many' tables may exist in a logical or physical data model but they are just shown
as a relationship with no cardinality under the conceptual data model.
Logical Design
The logical model is equipped with Entities, Constraints, Relationships, Primary Keys and Foreign
Keys and Columns
Entity-Relationship model

PHASE 3:
3.1 Create the database using MS ACCESS
3.2 Enter sample test data and perform various queries on the database using SQL

Create Table :

CREATE TABLE Loan(


loan_id NOT NULL PRIMARY KEY,
loan_amount int NOT NULL,
account_id int NOT NULL,
loan_type varchar NOT NULL,
app_date date NOT NULL,
end_date float NOT NULL,
repayment_sched date NOT NULL,
payment float NOT NULL,

FOREIGN KEY (account_id) REFERENCES Accounts(account_id)


);
--------------------------------------------------------------------------------------------------------------------------
CREATE TABLE Accounts(
account_id NOT NULL PRIMARY KEY,
balance float int NOT NULL,
iban int NOT NULL,
loan_id int NOT NULL,
cust_id int NOT NULL,
CONSTRAINT FK_cust_loan_id FOREIGN KEY (cust_id,loan_id),
FOREIGN KEY (cust_id) REFERENCES Customer(cust_id),
FOREIGN KEY (loan_id) REFERENCES Loan(loan_id)

);
--------------------------------------------------------------------------------------------------------------------------

Altar Table :

ALTER TABLE Accounts


ADD CONSTRAINT FK_PersonOrder
FOREIGN KEY (loan_id) REFERENCES loans(loan_id);

ALTER TABLE Customers


ADD Email varchar(255)

--------------------------------------------------------------------------------------------------------------------------
CREATE TABLE Customer(
cust_id int NOT NULL,
customer_name varchar NOT NULL,
customer_address varchar NOT NULL,
customer_email varchar NOT NULL,
password varchar NOT NULL,
loan_ID int NOT NULL,

PRIMARY KEY (cust_id),


FOREIGN KEY (loan_id) REFERENCES Loan(loan_id)
);
--------------------------------------------------------------------------------------------------------------------------
Insert:
INSERT INTO Customer(cust_id int, account_id int, customer_name VARCHAR(255),
customer_address VARCHAR(255), customer_email VARCHAR(255), password VARCHAR(255)
)
VALUES
(102334221, 30919, ‘Jason Todd’, ‘4 Hillview ave’, ‘Cash’, ‘%#@#**@’),
(102334456, 30920, ‘Richard Kimble’, ‘5 John’s Lane Estate’, ‘Car’, ‘&#$@@@’),
(101233349, 30921, ‘Cruz Taylor’, ‘1 Seaview Heights’, ‘tcruz@gmail.com’, ‘$@&$@*’),
(104334451, 30922, ‘Zander Belt’, ‘6 Cherry Mead’, ‘zanman@gmail.com’, ‘**##$@’)
(104443321, 30923, ‘Jeremy Tyler’, ‘20 Harbour-view Drive’, ‘jtmoney@gmail.com’, ‘*#$
$@@’);

--------------------------------------------------------------------------------------------------------------------------

INSERT INTO Loan(loan_id int, repayment_sched, deadline_date, app_date, loan_type,


loan_amount,cust_id)
VALUES
(123412341414, 30, 02/03/2021, 02/03/2020, Installment, 50000, 123123123),
(235252345233, 30, 03/01/2021, 02/02/2020, CC, 50000000, 123123123),
(112234234455, 30, 04/02/2021, 01/03/2020, ‘Small Business’, 50000, 123123123),
(134636363666, 30, 05/05/2021, 12/03/2020, ‘Home Imp’, 60000, 123123123)
(123235632567, 30, 06/03/2021, 30/06/2020, ‘School’, 300000, 123123123);

--------------------------------------------------------------------------------------------------------------------------

INSERT INTO Accounts(account_id int, balance float, iban int, loan_id int, cust_id int)
VALUES
(30923, 500000, 5648, 123412341414, 102334221),
(30920, 3000000, 5648, 235252345233, 102334456),
(30921, 1000000, 5648, 112234234455, 101233349),
(30922, 60000, 5648, 134636363666, 104334451)
(30923, 300000, 5648, 123235632567, 104443321);

--------------------------------------------------------------------------------------------------------------------------

Select (using Where, Group by, Having and Order by)

SELECT account_id
FROM Accounts
WHERE condition
GROUP BY balance
ORDER BY cust_id;
SELECT Loan(loan_id), loan_type

FROM Loan

GROUP BY loan_type

HAVING COUNT(loan_id) > 5

ORDER BY COUNT(loan_id) DESC;

References

https://www.visual-paradigm.com/guide/data-modeling/what-is-entity-relationship-
diagram/#erd-data-models-physical

https://www.w3schools.com/sql/

You might also like