[Import] an idea of Database Design

Source: Internet
Author: User

The idea of connecting to a post is that I don't want to query the remarks field every time I query, but I don't want to write very good SQL statements every time. Although I can use some SQL statement generators, but after all, the simpler the better.

So I want to find a way to design the database. For example, my database has five tables with note fields, so I think we can put all the notes of these five tables into one table, and my design can be like this:
The c_id, c_table1id, c_table2id, c_table3id, c_tabl4id, c_table5id, and c_comment fields in t_comment are the IDs of the table records, used to distinguish the table and record of the remarks.

For example, if I only use basic information in table 1 instead of remarks, I can directly use the following:
Select * From t_table1
To add remarks:
Select t_table. *, t_comment.c_comment from t_table1, t_comment where t_table1.t_id = t_comment.t_table1id
This is because there are few notes to be used, and the latter is almost unnecessary compared to the previous SQL statement. In a system, if there are some tables, its remarks are indispensable, and not every record will have remarks. This method can save a lot of SQL statements.CodeAnd saves a lot of resources.

In this way, the management and operation will be much better, and on average, the SQL statement writing will be much better ..... I decided to do this.

Of course, it is also a good practice to change the remarks field to the ID in the remarks table in each table, this depends on the Usage Frequency of the remarks to determine which method to use.

ArticleSource: http://computer.mblogger.cn/wucountry/posts/49781.aspx

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.