What is the separation of data stored in the database?

Source: Internet
Author: User
I received a lot of data from the front-end, such as A1, B1, A2, and B2... the properties of A (time) and B (content) are the same. in the database, I only want to use A text field to store it. Therefore, they need to be separated by characters, split the string when using it, but I don't know what character to use. I am afraid of this... I received a lot of data from the front-end, such as A1, B1, A2, and B2... the properties of A (time) and B (content) are the same. in the database, I only want to use A text field to store it. Therefore, they need to be separated by characters, split the string again when using it, but I don't know what character to use. I am afraid that the character is the same as the content in B, and the split is incorrect. give a suggestion.

Reply content:

I received a lot of data from the front-end, such as A1, B1, A2, and B2... the properties of A (time) and B (content) are the same. in the database, I only want to use A text field to store it. Therefore, they need to be separated by characters, split the string again when using it, but I don't know what character to use. I am afraid that the character is the same as the content in B, and the split is incorrect. give a suggestion.

Without considering indexes and performance:
1 if each content type is a number or a Chinese character without a separator, you can use commas or semicolons to separate it, such as 1, 2, 3, or happy, sad, if you need to use Like, use, 1, 2, 3, as shown in the following figure. (note that the start and end are separators)
2. if the content is a signed string or multiple types, serialize it to JSON or XML for storage, such as {time:, content: "Chinese people, code or something, it seems that it is not a problem ,.... "}
3 If the landlord really wants to exist together, it seems no problem to use multiple special symbols to separate them, for example, 2014-05-06 @ "people of China, code or something ,.... "
However, indexes cannot be used in the preceding method.
Another way of thinking, why do we need to save it like this?
1 A1, B1, A2, B2.. where are the properties of A (time) and B (content) the same? Why is the nature of time and content the same? after saving it, do you need to search by time or content? If so, the landlord's solution is wrong. according to the landlord's statement, there are always two fields A and B. why do they exist together?
2 If A1 and B1 are dynamic fields, are there any requirements for filtering based on conditions? If you only need a simple search, you can try database + full-text search. if you need to filter fields, such as time period filtering, consider Redis to implement this block service. if this happens frequently, consider the design abstraction rationality or consider databases such as MongoDb

I don't know whether the {key: value} format is suitable for you, because it is easier to load the JSON format back, and the format can also be checked. most languages support it...
But you don't need to use two columns, so you don't need to do these things... 'should you use ω?

You can use a separator to separate the separators as defined during retrieval,

If the scenario permits, you may try a database with a K-V-type storage structure.

Save the serialize array to the database.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.