In the design of dynamic websites, the importance of database design is self-evident. If it is not designed properly, it will be very difficult to query and the performance of the program will also be affected. Whether you are using mySQL or Oracle database, through formalized table design, you can make your PHP code more readable and easier to expand, which will also improve application performance.
Simply put, formalization is to eliminate redundancy and uncoordinated subordination in table design. In this article, I'll walk you through five progressive processes of formalization techniques you should know in your design. Thereby establishing a feasible and efficient database. This article will also analyze in detail the types of relationships that can be exploited.
It is assumed here that we want to create a user information table, which stores the user's name, company, company address and some personal favorites or URLs. At the beginning, you might define a table structure like this:
Zero status form
users
name company company_address url1 url2
Joe ABC 1 Work Lane abc.com xyz.com
Jill XYZ 1 Job Street abc.com xyz.com
Since no normalization is performed, we call this form of table a zero-state form table. Pay attention to the url1 and url2 fields---what if we need a third url in the application? This way you have to add an extra column to the table, which is obviously not a good idea. If you want to create a scalable system, you should consider using the first normalized form and apply it to the table.
First level normalized form
1. Eliminate duplicate groups in each table
2. Create a separate table for each set of related data
3. Use a primary key to identify each set Related data
The above table obviously violates the first provision above, so what does the primary key in the third provision mean? Very simple, it just adds a unique, auto-increasing integer value to each record. Through this value, two records with the same name can be distinguished. By applying the first level of normalization, we get the following table:
users
userId name company company_address url
1 Joe ABC 1 Work Lane abc.com
1 Joe ABC 1 Work Lane xyz .com
2 Jill XYZ 1 Job Street abc.com
2 Jill XYZ 1 Job Street xyz.com
Now our table can be said to be in the first level of formalization, it has been solved The problem of the restriction of the url field has been solved, but this processing has brought about a new problem. Every time we insert a record into the user table, we have to repeat all the company and user data. This not only makes the database larger than before, but also prone to errors. Therefore, it still needs to go through the second level of formalization.