mysql - Need help designing my invoice db structure -


I have a website where customers can buy membership.
Customers can visit payment history at any time and can see that Ben has bought.

I am trying to design DB to make an invoice, but something is not right for me.

My current setup looks like this:

  + ----------- + ------------ - + --------- + | Invoice | Invoice_item | Products | + ----------- + -------------- + --------- + | ID | ID | ID | | Fk_userID | Characters | Name | | | Volume | Price | | | Zodiac | | | Fk_invoiceID | | + ----------- + -------------- + --------- +  

This It seems logical that there is a foreign key in the context of invoice_item in product .
But what if a product has been removed? If they are related, the row in item_list will be deleted or set to tap.

And if you want to see the old invoice it will not work and the product is no longer available.

Then, should the product and item_list be related?

Once defined, you can not delete a product, so a product Add field - I am using an enum in this example, although it can easily be a set of INT or bools (i.e. archival), I use it for, but this is a different answer.

The most important thing is to make sure that the invoice line has been taken from the product in the order of pricing (and details), to ensure that any change in pricing or product name change in the future - Existing invoices do not affect.

I have used the technique (quite successfully) supersidying institutions in a database - so that the original record remains and a new version is inserted whenever the data changes. To do this, I add the following fields:

  • Current ID
  • supersededById
  • previous ID

This creates It asks for a bit more cumbersome - but especially for the address it is important to ensure that the invoices remain intact and changes of that address do not appear in the invoice - eg Changing company name should not change the invoices raised earlier.

Enter image details here

  create table Do not tap the 'invoice' (`id`, not the primary key (` id`)); Do not tap the tab 'Invoice item' (`id`), 'DRD' VARCHAR (200) tap,` value DCIMAL (11,3) tap, `quantity DCIML (11,3), total` DCIML 11.3) Not zero, `fk_id_Invoice` can not be denied, do not` fk_id_Product`; do not give primary key (`id`); Do not create the tablet `PRODUCT '(` id'), tap AUT agreement, `value` DCIML (11,3) NOUL,` name 'is not VARARA (200) tap,' status' ENUM null, primary (`id `)); Add optional table 'invoice item' Add foreign key (fk_id_Invoice) Reference 'invoice' (`ID`); Optional table 'invoice item' Add foreign key (fk_id_Product) Reference `product` (` id`);  

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -