Horizontal and vertical tables of the database

Source: Internet
Author: User

Click

Let's talk about the concept of horizontal table and vertical table. Let's take a look at the two figures below:

The first figure is a horizontal table, with a row representing an object record. This is the form of our traditional design table.

The second figure is a vertical table. Its row of records is used to indicate the ing between the attribute name and the attribute value of a student. For example, there are two attributes (name and gender ), in the vertical table, two records are used to represent a student.

We can see from the above that the benefit of a horizontal table is that it is clearly visible and clear, but there is a drawback. If you want to add a field to this table, you must recreate the table structure. In this case, you only need to add one record to the vertical table to add a field. The cost is far smaller than that of the horizontal table, but the data description of the vertical table is not very clear, in addition, there will be a large number of databases, and the advantages and disadvantages of both are that. Therefore, we should design a table structure that is not easy to change into a horizontal table, and design a table structure that is easy to change frequently as a vertical table.

In actual development, it is often necessary to convert the form of horizontal and vertical tables from each other. Here we paste the form of converting data from the vertical table to the horizontal table display.

?
1234 Selectstudent_no, max (decode (field_name, 'student _ name', field_value) asstudent_name, max (decode (field_name, 'student _ sex', field_value) asstudent_sex into metadata;

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.