mysql optimization - the basic principles of database design

mysql optimization - the basic principles of database design

First, the database design three paradigms

The first paradigm: field having atomic
atoms refers to the database are not all the fields is divided again in the following table do not satisfy the atomicity, beginning and end of the field can be split into two fields beginning and the end.

id starting point end point
1 Beijing Shanghai
2 Beijing - Guangzhou

The second paradigm: the elimination of part of the primary key dependent
dependency refers database table, field by field B A can be determined, which is called the A B dependent.
Refers to partially dependent on the primary key of the table when the database is a composite primary key (A, C), only the B and A depends, in part dependent upon this case referred to.
The correct way to create a business logic is independent of idthe primary key, on the other fields there is only a unique primary key dependent, i.e., meet the requirements of the second paradigm.

Third Pattern: Elimination of the primary transfer key dependent
transfer dependency: If A field B field dependent, C field dependent field B, the C field is composed of fields A transfer dependence.

id Train No. Order of seats starting point end
1 D705 Car 11 04 Beijing Shanghai
2 K507 15 No. 77 car Beijing Chongqing

As shown above start and end of the train are primary key idgenerating part dependent (start, end -> Train Number -> ID)
Solution: sub-table, the transmitting part of a separate built-dependent table.

Train No. starting point end
D705 Beijing Shanghai
K507 Beijing Chongqing
(Liezi inappropriate do not worry)

It should be noted here that the three paradigm, the second paradigm must meet in first normal form, third normal must satisfy the first and second paradigm.


Second, the design principles of database fields

1. Try to use an integer to indicate a string
using a string that represents an integer number has two advantages:
-> an integer typically less than the storage space occupied by the string
-> 2 number of integer arithmetic speed


2 using fixed-point represented float
floating point arithmetic stored in the computer and easily distorted, for high accuracy requirements banking amount of a class of data, we can use fixed-point decimal storage, defines decimal (P, D) can create a bit integer up P bit decimal bit fixed-point D up. 3. use the smallest possible data type 4. avoid the use of a non-empty fields 1. null other fields can not participate with operators other than the additional storage space required 2. null 5. Note the complete field, field name having logical meaning 6. single field should not be excessive 7. using the reserved field





nullis not null







Third, the application association table

there may be between the two tables mysql three special relations 一对多, , 多对多, 一对一corresponding to the three pairs of the same name association table.
1-to-many association table -------- commonly associated foreign key is provided a multi- one
2-many association table -------- by creating a first intermediate table stores two primary key correspondence between the intermediate table and the table are two entities formed two-many relationship.
3. one association table ---------one relationship, a table can be used directly to store. However, if the number of fields in the table excessive or unusual part of the field, can be considered sub-table, two tables share the same primary key.

Guess you like

Origin www.cnblogs.com/LLBoy/p/11462081.html
Recommended