Answer the question
In order to leave comments, you need to log in
How to store text in database?
Faced the following question, the following tables are planned in the database,
For example:
Users
Posts
Companies
Groups
Each of these tables, in addition to the main fields, should have a description field - a brief description / explanation of the corresponding entity. The type of this field is text.
There are several options:
1) Add a text field to each of the tables:
Users (description)
2) Create an additional table with a description for each table:
Users (description_id)
Users_description (id, description)
3) Create a separate table for the descriptions fields of the entire site
Descriptions (id description)
Users (description_id)
Groups (description_id)
4) Variation of the 3rd point, with making the connection into the table descriptions
Descriptions (id, sourceType, sourceId, description)
Where sourceType in ('users', 'groups', 'posts', ... ), and sourceId = identifier of the entity
I like option 3 and 4.
Which option do you prefer?
Answer the question
In order to leave comments, you need to log in
1) Yes, mine is obvious here. You have your own description for each entity, so add it to the tuple. Accordingly, the first option is the most acceptable.
2) What for?
3) In this case, you should have end-to-end IDs.
4) I don't understand.
In my opinion, you just overworked yourself and thoughts formed prominences in your head :)
Good.
Of course, the first option. The rest can be considered only if you really want the most ideal optimization, but.
1. These fields will probably not participate in your queries, they simply do not need indexes or optimization.
2. To select data from them, if it is still required, for example, to create a description of the database, tricky requests will be needed. To create them and to implement everything except the first option, it will take time, which is better spent on developing base
3. All these cunning requests will not be accepted by any automatic description generation system.
4. It is unlikely that the descriptions coincide so often and there are so many of them that their optimization will speed up the selection.
In general, the game is not worth the candle, colleague.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question