简体   繁体   中英

Normalisation from 1NF to 3NF

If I have the following table which is currently in 1NF:

在此处输入图片说明

I am required to decompose this table into 3NF.

I would then have (correct me if I am wrong):

Customer(Customer ID-PK, Customer Name)
Branch(Branch ID-PK, Branch Name, BSB)
Account(Account Type-PK, Account Name)

What would I have for Account Details? I'm thinking something like:

Account Details (Account Number, Customer ID, Branch ID, Account Type, Account Balance)

I'm stuck on what to make the primary key of this main table as there are multiple customers on a single account number.

Would I be needing to use a composite primary key with Account Number and Branch ID?

What other/better options do I have here?

You can create structure as follows,

Customer(Customer ID-PK, Customer Name)
Branch(Branch ID-PK, Branch Name, BSB)
Account(Account ID-PK, Account Number, Account Name, Branch ID, Account Type, Account Balance)
Account_Customer ( Account_Customer_id-PK, Account id, Customer ID)

You have to keep account related information at one place ie in account table itself. Also for Account_Customer you can add active flags or from & to dates to keep more Customer & account related

As you mentioned, one account has many customers. Do you also have other criteria like one customer can have many accounts ? If this is the case, then you have to design with many-to-many relationship. Something like

Customer(PK, CustomerName)
Account(PK,AccountId,...)
AccountMapping(PK,(Account.PK/Customer.PK) AS FOR,(Account.PK/Customer.PK) AS TO)

I'm assuming that the organization being modelled is a bank.

Given the sample data, it appears that the Branch ID, Branch Name and BSB are all associated with a specific branch, and each of the columns is a candidate key (could be 'the' primary key).

One of the 3NF tables should be:

Branch:  Branch ID, Branch Name, BSB — Branch ID nominated as PK

Only two bits of data are recorded for each customer: the customer name and their customer ID. Since names can repeat, we'll assume the the customer ID is the candidate key.

One of the 3NF tables should be:

Customer: Customer ID, Customer Name — Customer ID nominated as PK 

Given that the first two data rows and the last all identify a/c 9047 1234 but the account type information is different, the a/c number is not unique across all branches in the bank. Based on the data shown, the combination of account number and Branch ID should be unique (and hence the PK). However, a given account can be shared by more than one customer – witness the first two rows of data.

Consequently, one of the 3NF tables should be:

Account: Account Number, Branch ID, Account Type, Account Balance, Account Type, Account Name
— PK(Account Number, Branch ID)

And another should track the customer(s) associated with a given account number. Again, the table shown is 'all key', with the Account Number and Branch ID forming one foreign key and the Customer ID being another.

Account_Customers: Customer ID, Account Number, Branch ID

So, I think you need 4 tables. The primary key columns are marked with an asterisk.

  • Branch: Branch ID*, Branch Name, BSB
  • Customer: Customer ID*, Customer Name
  • Account: Account Number*, Branch ID*, Account Type, Account Balance, Account Type, Account Name
  • Account_Customers: Customer ID*, Account Number*, Branch ID*

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM