Z
Z
zxcursed2021-09-28 22:21:56
MySQL
zxcursed, 2021-09-28 22:21:56

How to design a word database?

It is necessary to store a set of words / phrases in the database, while being able to conveniently select using php / react js and update in the same way, what is the best way to do this? There will be no more than 100-150 words
In my head, the idea is to create a varchar cell and write everything into it, separated by commas. (then it is necessary to select it all more conveniently and push it into one array)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stefan, 2021-09-29
@MEDIOFF

| words |
+ ------ +
| lala |
| ... |
So, a cell, yes, Varchar, store each word separately, it’s not convenient to select through a comma, read about normalization

A
Akina, 2021-09-29
@Akina

The idea in my head is to create a varchar cell and write everything into it, separated by commas.

From the point of view of working with a DBMS, storing an array of data as a CSV value is an extremely unfortunate option. And very problematic in processing. However, if we are talking about a fairly static data array of a hundred records, this is an acceptable option.
A normalized structure that is easy to handle might look like this, for example (of course, this is just a piece for storing words and phrases):
CREATE TABLE words (
    word_id INT AUTO_INCREMENT PRIMARY KEY,
    word VARCHAR(255) UNIQUE NOT NULL
);

CREATE TABLE phrase (
    phrase_id INT NOT NULL,
    FOREIGN KEY (phrase_id) REFERENCES phrases (phrase_id),
    word_id INT NOT NULL,
    FOREIGN KEY (word_id) REFERENCES words (word_id),
    word_position INT,
    PRIMARY KEY (phrase_id, word_position)
);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question