L
L
LamerFromSpace2019-06-01 22:42:25
Database design
LamerFromSpace, 2019-06-01 22:42:25

How to store a purchase receipt in the database?

How to store multiple IDs of purchased items for one purchase?
Table:

CREATE TABLE magazdb.purchase ( 
  id                   int UNSIGNED NOT NULL  AUTO_INCREMENT,
  purchase_date        datetime  NOT NULL DEFAULT CURRENT_DATE ,
  description          text    ,
  good_list            json, -- Вот в этом столбце хотелось бы хранить список ID купленных товаров,  что то вроде json формата
  CONSTRAINT purchase_id PRIMARY KEY ( id )
 )

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
nrgian, 2019-06-02
@LamerFromSpace

Your desires just contradict the principles of relational databases.
According to the classics, there is a separate table with a list of goods and a separate table with checks. And the connection between them, therefore, in fact, they call databases relational.
Ignoring this requirement - means an ass in the future.
But, if you don’t need to do anything smart with these products (for example, search for them or sort them, monitor integrity when changing the product catalog), then you can do that.
However, it is not clear here - what causes difficulty?
You take and write down these IDs in any convenient form, even as a simple string separated by commas, even in a JSON array - but whatever you like.

N
NewDevLab, 2019-06-01
@NewDevLab

Table Receipts and Table Goods

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question