Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Normalize SQL database

I'm creating a database for a project and I'm a little confused about how normalization applies to my schema. Everytime a loan is aproved for a customer, they have 2 options a check or an EFT, so I want to know wheter the loan was a check or EFT.

This are my 3 tables:

Loans

id_loan (PK)
product
amount 
status

Checks

id_check (PK)
id_customer
amount

EFT

id_eft (PK)
id_customer
amount

Then I created a 4th table to establish a relationship between loans and money disposal.

Disposal

id_payment (PK)
id_loan (FK loans)
id_disposal (FK checks or EFT)
disposal_type

In this table I store whether the loan is related to a check or an EFT, disposal_type field is a varchar with two possible values "check" or "EFT". id_disposal field acts as a foreign key for two tables.

The problem is that I think my database isn't normalized with this structure, am I right? What would be the best way to solve this?

like image 298
Jorge Zapata Avatar asked Jul 22 '26 18:07

Jorge Zapata


1 Answers

You need something like the attached. Note that the customer_loans table is kind of extraneous and overkill, but if there's any columns that relate to the customer and the loan, and not the customer's loan payments, that's where it would go.

Loans Schema

like image 158
Wil Avatar answered Jul 25 '26 07:07

Wil



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!