J
J
jenya77712018-07-03 16:20:36
PostgreSQL
jenya7771, 2018-07-03 16:20:36

How to organize a database?

Hello, how to properly organize the database. I will have a table in which promotional codes will be stored, their number can be very large, and there will be 4 types of promotional codes, how to organize their storage?
I thought to make 4 tables for 4 types of promotional codes, and add a number to the end of the protocol, which will indicate the type of promotional code. But if I need to pull out all promotional codes by a certain attribute, for example user=99 from all tables, then there will be 4 queries, as I understand it, this will not be very good, what should I do in my situation?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Ruslan., 2018-07-03
@jenya7771

I would make one table with promotional codes and think over which indexes would be needed based on possible use cases.
One table because now you have 4 types, and then there may be more of them and for this you will have to add new tables and rewrite queries?
In addition, many tables will complicate queries, especially where it will be necessary to build reports.
To prevent the table from growing too much, you can provide a lifetime for promotional codes and delete or transfer expired ones to an archive table.

S
SagePtr, 2018-07-03
@SagePtr

Just one table for all types, in addition to promotional codes, there are user and type columns.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question