Database regularization and Design techniques (2)

Source: Internet
Author: User
Technique | design | data | Database Second level normalization form

1. Create a separate table for fields that are applied to more than one record

2. Use a foreign key to correlate the values of these tables


We put the value of the URL in a separate table so that we can add more data at a later time without having to worry about producing duplicate values. We also associate these fields with primary key values:

Users

UserId Name Company Company_address

1 Joe ABC 1 Work Lane

2 Jill XYZ 1 Job Street

URLs

Urlid Reluserid URL

1 1 abc.com

2 1 xyz.com

3 2 abc.com

4 2 xyz.com

As shown above, we have created a separate table in which the primary key userid in the users table is now associated with the foreign key reluserid in the URL table. It seems that the situation has improved markedly. But what if we have to include an employee record for ABC company? Or more, 200? So we have to be heavy.
Reusing the company name and address is obviously not redundant. So we will apply the third level regularization method:

Third-level regularization form

1. Eliminate fields that are not dependent on the key

The company name and address are not related to the user ID, so they apply with their own company ID:

Users

UserId name Relcompid

1 Joe 1

2 Jill 2

Companies

Compid company Company_address

1 ABC 1 Work Lane

2 XYZ 1 Job Street

URLs

Urlid Reluserid URL

1 1 abc.com

2 1 xyz.com

3 2 abc.com

4 2 xyz.com

In this way we associate the primary key comid in the companies table with the foreign key named Relcompid in the users table, and even if we add 200 employees to the ABC company, there is only one record in the companies. Our users and URLs tables can be constantly expanded without worrying about inserting unnecessary data. Large department
Divided developers think that after three-step normalization is enough, the database design has been able to easily deal with the burden of the entire enterprise, this view in most cases is correct.

We can pay attention to the URL field-do you notice the redundancy of the data? If the HTML page that gives user input to these URL data is a text box, can be entered arbitrarily, this is not a problem, two users enter the same favorites less probability, however, if it is through a drop-down menu, only let the user select two URL input, or more. In this case, our database can also be optimized at the next level--step fourth, for most developers, this step is ignored because it relies on a very special relationship--a many-to-many relationship that has not been encountered in our applications yet.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.