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. Regardless of
whether you are using mySQL or Oracle database, formalized table design 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 through five progressive processes to teach you the 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 as follows:
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 rule above, so what does the primary key in the third rule mean? Very simple, it just adds a unique, automatically 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