当前位置:网站首页>Physical design of database design (2)

Physical design of database design (2)

2022-06-26 04:28:00 good writings make people copy them

What does physical design do

One . Choose the right database management system  

Oracle、SqlServer、MySql And PgSQL

  • Copyright 、 Cost considerations :

  • Functional considerations :

Oracle: A good one in the industry DBMS, A high performance , It is suitable for large transaction operations .

  • Operating system considerations :

SqlServerL Only support Windows Under the system

Oracle、MySql And PgSQL: Can support linux System 、windows System

  • Development language considerations :

If you use .net development language , Use SQLServer better

  • Application scenario considerations :

mysql And PgSQL Applicable to Internet projects

Oracle、SqlServer Applicable to enterprise level projects (Oracle, E.g. carrier level 、 financial , Because it has good scalability , High safety ,SqlServer: Small and medium-sized enterprises erp)

Introduce Mysql Common storage engines

 

Two 、 Define database 、 Naming conventions for tables and fields

All object naming principles :

1. Readability principle

  Be careful : Case naming ( hump ), yes , we have DBMS Sensitive to case , such as Mysql

2. The principle of expressiveness

The name of the object should be able to describe the object it identifies .

for example : Table name , It can reflect the stored data content

          For stored procedures , The stored procedure name should reflect the function of the stored procedure

3. Long name principle

Use as few or no abbreviations as possible .

For databases DB Any object other than the name

Such a name , When only looking at the name of the watch 、 Field name , I have no idea what the watch is for . During development and post operation and maintenance , Poor readability , Need to rely entirely on manuals .

3、 ... and . According to the selected DBMS The system selects the appropriate field type

  Selection of data type of column :1. It will affect the cost of data storage space ,2. Affect the performance of data query

The principle of field type selection :

  When a column can select multiple data types , Should be Number type is preferred , Next is the date or binary type , Finally, the character type .

For the same level of data type , Should be Give priority to data types that take up less space .

 

 Mysql stay MySQL For internal use 4 Bytes INT Type to store timestamp data , Timestamp type , It can only be stored in 2038 year , Because now 2020 Years. , Use it with caution . Empathy ,int Type to store time should also be used with caution !

  The above principles are mainly considered from the following two perspectives :

1. When comparing data ( Query criteria 、join Conditions and order ) When waiting for operation : The same data , Character processing is often slower than number processing

 2. In the database , Data processing is in pages , The smaller the length of the column , Good for performance .

How to select field type in database :

  •  char And varchar How to choose ?

1. If the length of data to be stored in the column is almost the same , Consider using char; Otherwise, we should consider using varchar . Such as : ID number , cell-phone number

2. If the maximum data length in the column is less than 50Byte, Generally, we also consider char( If the column is rarely used , Based on saving space and reducing I/O The consideration of , Or choose to use varchar)

3. In general, it is not appropriate to define more than 50Byte Of char Type column .( almost 15 Characters )

  • decimal And float How to choose

 1.decimal For storing accurate data , Two float Can only be used to store imprecise data .

2. because float The cost of storage space is generally higher than decimal Small , Therefore, imprecise data is preferred float type

  • How time types are stored

1. Use int To store the advantages and disadvantages of time fields

advantage : Field length ratio detetime Small

shortcoming : Inconvenient to use , To convert a function

Limit : It can only be stored in 2038-01-19 11:14:07, because 2^32 by 2147483648

2. Time granularity to store  

year 、 month 、 Japan 、 Hours 、 branch 、 second 、 Zhou

Four 、 Other considerations for database design :

1. How to choose a primary key

2. Avoid using foreign key constraints

  •   Reduce the efficiency of data import , The impact of high concurrency environment is very serious
  • Increased maintenance costs
  • However, foreign key constraints are not recommended , But the associated column must be indexed

3. Avoid using triggers

1. Reduce the efficiency of data import

2. Unexpected data exceptions may occur , Especially when business requirements change

3. Complicate business logic  

4. About reserved fields

 1. Unable to know exactly the type of reserved field .

2. Unable to accurately know the contents stored in the reserved field

3. The cost of maintaining the reserved fields later , The cost of adding a field is the same

4. strictly prohibit Use reserved fields

 

5、 ... and . Anti normal design

  For the sake of performance and reading efficiency , Appropriately violate the requirements of the third paradigm , and A small amount of data redundancy is allowed . Space for time .

 

Why anti paradigm

1. Reduce the number of table associations

2. Increase data reading efficiency

3、 The anti paradigm design must be moderate

 

原网站

版权声明
本文为[good writings make people copy them]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202180531084722.html