Database design skills 2

Source: Internet
Author: User
1. create an independent table for the fields of multiple records in the application. using a foreignkey to associate the values of these tables, we place the url values in an independent table so that we can add more data in the future, there is no need to worry about duplicate values. We also associate these fields with the primary key value SyntaxHighlighter. all ();

1. create an independent table for the application's fields in multiple records
2. associate the values of these tables with a foreign key.

We put the url value in a separate table so that we can add more data in the future without worrying about duplicate values. We still pass
Through the primary key value to associate these fields:
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, an independent table is created. the primary key userid in the users table is now associated with the foreign key relUserId in the url table. Current situation
It seems that it has been significantly improved. But what if we want to add an employee record for ABC? Or more, 200? In this way, we must
Reuse of company names and addresses is not redundant. Therefore, we will apply the third-level normalization method:
Level 3 Regularization
1. eliminate fields that do not depend on the key
The company name and address have no relationship with the User Id, so their applications have 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, even if ABC joins


There are only one record for 200 employees in companies. Our users and urls tables can be expanded constantly without worrying about inserting unnecessary data. Most
Developers think that the three-step normalization is sufficient. the database design can easily handle the burden on the entire enterprise.
Number is correct.
We can pay attention to the URL field-have you noticed data redundancy? If the HTML page for users to enter the url data is a text
Box, if you can enter any information, this is no problem. The two users have less probability to enter the same favorites. However, if you use a drop-down menu
Select two URLs or a bit more. In this case, our database can also be optimized at the next level-step 4 for most
For the sender, this step is ignored because it depends on a very special relationship-a many-to-many relationship, which has never been encountered in our applications.

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.