This article uses an example to illustrate the method of optimizing the MYSQL database table structure. Share with you for your reference, the details are as follows: Choose the right data type1. Use the smallest data type that can hold your data 2. Use simple data types. Int is easier to process in MySQL than varchar type. 3. Use not null to define fields as much as possible 4. Use text type as little as possible. If you have to use it, it is best to consider splitting the table Use int to store date and time, and use Use bigint to store IP addresses, and use Normalization and denormalization of tablesNormalization refers to the specification of database design. The current normalization generally refers to the third design paradigm, which requires that there are no non-key fields in the data table for any candidate key fields. The transfer function dependency conforms to the third normal form. Tables that do not conform to the third normal form have the following problems: 1. Data redundancy: (classification, classification description) records will be kept for each product 2. Data insertion/update/deletion exceptions Normalized operation: Denormalization means to increase redundancy appropriately for tables that originally conform to the third normal form for the sake of query efficiency and considerations, so as to achieve the purpose of optimizing query efficiency. Denormalization is an operation that exchanges space for time. example: Denormalize the table Denormalize order information: Vertical split of tableVertical splitting is to split the original table with many columns into multiple tables, which solves the problem of table width. Usually vertical splitting can be done according to the following principles: 1. Store infrequently used fields in a separate table. 2. Store large fields independently in a table. 3. Put fields that are often used together. Horizontal SplitThe purpose of horizontal splitting of tables is to solve the problem of too much data in a single table. The structure of each table in the horizontal split is exactly the same. Commonly used horizontal splitting methods: 1. Perform a hash operation on customer_id. If you want to split it into 5 tables, use 2. Store data in different tables for different hashIDs Readers who are interested in more MySQL-related content can check out the following topics on this site: "MySQL query skills", "MySQL common functions summary", "MySQL log operation skills", "MySQL transaction operation skills summary", "MySQL stored procedure skills" and "MySQL database lock related skills summary" I hope this article will be helpful to everyone's MySQL database design. You may also be interested in:
|
<<: Node.js makes a simple crawler case tutorial
>>: Detailed explanation of generic cases in TypeScript
The installation and configuration method of MySQ...
Preface In order to meet the high availability of...
Table of contents Basic database operations 2) Vi...
When updating a record in MySQL, the syntax is co...
<br />A year ago, there were no articles abo...
What is a table? It is composed of cell cells. In...
The first step is to create a mysql container doc...
1. Right-click the project and select properties ...
1. What are the templates for ASP.NET Web applicat...
question How to modify CSS pseudo-class style wit...
Table of contents 1. Introduction to pid-file 2.S...
<br />Adding pictures reasonably can make a ...
On the server, in order to quickly log in to the ...
This article uses an example to share with you a ...
This article mainly introduces the solution to th...