On database design two or three things

Source: Internet
Author: User

As programmers, the design of the database before the program is very important, this will directly related to the code writing work, here to talk about the database design process some of the details of the problem.

A. Field selection for the primary key of the data table (Id,code,number)

        id (numbering) is generally selected guid The string in this format is a string of globally unique strings. When a program needs to invoke a database of the same structure on different platforms, it is recommended to use the guid code (encoding) is generally a string of non-full numbers, such as a string of letters mixed in number format. In particular, when designing an object model that has a multilevel association relationship. such as the personnel department structure, commodity multilevel classification and other tree-like structure of the relationship between the object model (see).

650) this.width=650; "src=" http://img.my.csdn.net/uploads/201301/04/1357312760_2424.jpg "align=" Middle "width=" 676 "height=" 280 "style=" border:none;/>

As shown in the departmental structure, set up a departmental code in the databaseCode, the number of colors in the structure. The advantage of this is that it is easy to get information from the department based on the code. For example, to get the precinct.3(0103), you can intercept the first four digits of the department code in the table to determine if it equals0103, so you can get the precinct.3It's very easy to code all the departments below and then read the information from the people information sheet. Number(serial number) is generally used in the identification records need continuous counting, usually is the system self-growth generated or automatically generated by the program. For example, if there is more than one object, it can be distinguished by ordinal. Compared to library, the same book there are many times, you can use a serial number to distinguish. At the same time, it is also very intuitive to see how many of the same individual records of the object, if the data has not been deleted. The design of the database can be based on specific circumstances to choose, so as to achieve a multiplier effect.

Two The idea of space-changing time

         when a primary table and multiple sheets exist from the primary foreign key relationship, It is common practice to access primary key information from the table records in the primary table. When reading this information, it is necessary to combine two and more than two tables for data reading and combination to get the information we need. In the database idea, it is mentioned that the database design should avoid data redundancy as much as possible, which can save the space of data storage. However, in today's society. Hardware technology rapid development of the era, storage media storage space can be more and more large, the basic need not consider the problem of database occupancy. Despite the rapid development of storage media, computer processing speed is difficult to keep up. Therefore, when designing the database, consider how to make the operation to be able to respond quickly, so as to save the user waiting time. This is the idea of space-changing time. For example, the primary table needs to store the user name in the user table and the user table data is large, then consider storing the user's name directly in the primary table instead of saving the primary key information for the user information record. This way, we can only query the main table to get the information we need without having to go to the Federated User table to query. Of course, this is not a common practice, there are a few points to note. First of all, the field from the table should be basically no longer associated with other business processes, such as I only need to display this name at the time of the query, and do not need to re-error query or modify the other series of business operations. In addition, this data needs to be reviewed as a historical record, so as far as possible to store information ontology rather than the main key of the table record of the information ontology. Otherwise, when the table information is modified, when you query the record again, you will find that the situation is inconsistent with the actual situation. For example, a company's courier delivery is the company's front desk, but the front desk will always have personnel changes, people are not, but the work number is still in the transfer to the new use. The sender's name is stored directly when the sender's information is recorded. Sometimes, we also choose to store the primary key from the table and the information body directly in the main table. For example, save the user's name while storing the user's work number. In this way, the main table information can be obtained directly according to the work number at the time of retrieval, and the user's work number and name are obtained. Although there is data redundancy in this case, it is not a good idea to do so for the efficiency of the query.

Finally, mention it. The design of the database should be based on the actual situation, supplemented by theory, taking into account implementation efficiency. In different cases, these practices are not necessarily suitable, specific analysis of the situation.

This article is from the "Swaying Kite" blog, please be sure to keep this source http://pinzi.blog.51cto.com/4845903/1603837

On database design two or three things

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.