W
W
willlli2014-12-10 02:00:16
PHP
willlli, 2014-12-10 02:00:16

What is the best way to organize the database structure and what happens if the value is null?

I am designing a database, but there are too many parameters for several dozen categories, which may simply not be filled in. How to deal with this? Here, for example, I'll take the structure of the store. "Most suitable"
I wanted to push everything into one table from the beginning, but I understand that it's terrible ...
30cb396e222745ce97ffaa4540fc83c7.png
But in any case there will be empty blank fields ... Maybe someone has a solution?
+ The first option will not duplicate the "param*" columns
- a bunch of empty fields, compared to the second option.
Although you are more experienced and understand.
It's just impossible to predict whether there will be 10 parameters or 20, the database will be dynamically created.
For example, let's take the same "easier to explain" products
, each product will have id name count param1 param2 ...
the second product will have id name count param1 param2 ... param6
and the third product will have id name count param1 param2 ... param13
and they are all in the same category, how to store such options?
It turns out that you need to create a table with
id name count param1 - param13 and as a result there will be 13 columns with parameters that will be partially
filled
. solving such problems?
The parameters are needed for the search, so I would just combine everything and push it into param.
There was an idea for duplication.
Separate tables are created for searching, a table with basic data that contains json parameters or plain text in the form parameter1: value1; parameter2: value2 .. etc. or 1: 1; 2: 2 .. etc. and search already by tables.
In short, I don’t know, multilingualism is done on the same principle, only there is no that in the 1st case 8 cells are filled in the other 4 and 4 empty ...
I hope the question is clear, thanks for the help, I’ve been trying to solve for 21 days from everything I realized that the values ​​are null or a blank cell in the database is terrible, but if % 55-60... you can hang up

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Anatoliy Mikhailov, 2014-12-10
@yamaoto

Usually, to add parameterization, a separate table for parameters is added:

/* параметры */
CREATE TABLE Parameters (Id INT NOT NULL PRIMARY KEY, Name NVARCHAR(150) NOT NULL)
/* возможные значения параметров */
CREATE TABLE ParametersOptions (Id INT NOT NULL PRIMARY KEY, ParameterId INT NOT NULL, Value NULL NVARCHAR(150))
/* привязка конкретному товару определенного значения параметра */
CREATE TABLE ParametersValues(Id INT NOT NULL PRIMARY KEY,ProductId INT NOT NULL, ParameterId INT NOT NULL, Value INT NOT NULL)

Here the Value column of the ParametersValues ​​table is specified as optional.
You can also add a category navigation table so that you can associate a series of options with a specific category

V
Vladimir, 2014-12-10
@azrail_dev

The vertical structure will help you.

M
Matvey Mamonov, 2015-01-08
@eucalipt

I didn't understand the question a bit, I apologize if the answer is not in the barrel.
Are we talking about the parameters of the goods stored in the table?
If so, then I always use the most simple method, IMHO. All product parameters can be stored as one line, the parameters can be listed separated by commas. And then pull out this entire line from the database and simply split it into an array in the places where commas are present.
Again, I apologize if the answer is off topic.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question