Please guide me if I’m on right track.
I’m trying to create database schema for Mobile Bill for a person X and how to define PK, FK for the table Bill_Detail_Lines.
Here are the assumptions:
- Every customer will have a unique relationship number.
Bill_nowill be unique as it is generated every month.Xcan call to the same mobile no every month.Account_nois associated with every mobile no and it doesn’t change.
Schema:
table: Bill_Headers
Relationship_no - int, NOT NULL , PK
Bill_no - int, NOT NULL , PK
Bill_date - varchar(255), NOT NULL
Bill_charges - int, NOT NULL
table: Bill_Detail_Lines
Account_no - int, NOT NULL
Bill_no - int, NOT NULL , FK
Relationship_no - int, NOT NULL, FK
Phone_no - int, NOT NULL
Total_charges - int
table: Customers
Relationship_no - int, NOT NULL, PK
Customer_name - varchar(255)
Address_line_1 - varchar(255)
Address_line_2 - varchar(255)
Address_line_3 - varchar(255)
City - varchar(255)
State - varchar(255)
Country - varchar(255)
I would recommend having a primary key for
Bill_Detail_Lines. If each line represents a total of all calls made to a given number, then the natural PK seems to be(Relationship_no, Bill_no, Phone_no), or maybe(Relationship_no, Bill_no, Account_no).If each line instead represents a single call, then I would probably add a
Line_nocolumn and make the PK(Relationship_no, Bill_no, Line_no).