We all know that there are many types of invoices
Take the invoice for my environment as an example
Invoices include VAT invoices, which are divided into general invoices and special invoices
Both general and special invoices have columns such as invoice code
, invoice number
, invoice date
, check code
, unit price
, total amount
, etc.
In addition, the special invoices has tax exemption
, address
, phone
, bank account
In addition, there are also travel invoices
Travel invoices can be simply divided into the following categories
Air tickets, train tickets, bus tickets, ferry tickets, online booking tickets, taxi tickets
All invoices have the following columns
Departure time
, Departure place
, Arrival time
, Arrival place
, Amount
Airplane invoices and online car-hailing invoices have an invoicing date
Except for train invoices, other invoices have invoice number
, and air tickets have invoice code
Air tickets have tax amount
, aircraft invoice number
, service company
Train tickets have a train ticket number
Online booking tickets and taxi tickets have their own ticket numbers
There is also a type of invoice called a fixed invoice
This type of invoice has amount
, invoicing time
, and its own invoicing number
The toll invoice is a fixed invoice, but it has entrance
and exit
and departure time
I know there might be some confusion and impatience when you see this -- 'How could it be so troublesome! '
But that's not the point, it's history for me
What I want to ask is, when a scenario like the above--"they are all called Invoices, but they are all different, no single Invoice can be fully used as the base class for all Invoices"--how should I store it?
I have tried to store them separately, and the result is that we have ten tables with different invoices, and most of them have the same fields. Such a table design brings great trouble to other members' development, so that we have to Spend a week standing still and finally refactoring the database
Putting things together without thinking is really convenient for storage and saves trouble, but is it necessary to do this for all such scenarios?
I want to know the boundaries of this question
How should I design the tables of the database for different entities that have common columns and cannot extract non-abstract base classes