SQL anti-Pattern Learning Note 8 Multi-column Properties

Source: Internet
Author: User

2014-10-13 10:32:12

target : store Multi-valued properties

anti-pattern : Create multiple columns. For example, a person has multiple phone numbers, landline numbers, mobile phone numbers and so on.           

1, query: Multiple columns, query may have to use in, or more or;

2, add, delete to ensure uniqueness, determine whether there are values: these are very troublesome;

3. The number of columns in the field cannot be determined.

how to recognize anti-patterns : May be anti-pattern when the following conditions occur

1. What is the number of dynamic columns that should be supported?

2. How can I query multiple columns at the same time in a SQL query?

Rational use of anti-patterns :

In the case of dictation, a property may have a fixed number of candidate values, and their storage location and order are fixed. In this case, you can use anti-patterns.

Solution : Create a subordinate table that uses only one column to store multivalued properties.

Define a foreign key in the subordinate table that associates the value with the primary key ID in the target table.

conclusion : Stores values that have the same meaning in the same column.

SQL anti-Pattern Learning Note 8 Multi-column Properties

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.