database table Design 1

Source: Internet
Author: User

Time: 2015.4.21.17:50

2 years of learning programming, the first analysis of requirements. Summarize my understanding of the building table.

1. The table is stored in the database, and the table is a collection of objects.

2. The fields in the table are object properties.

3. The relationship between tables and tables is 1:1,1:n or n:1,n:n.

4.1:1 of understanding

Team Address

Team ID Team Name Address ID (foreign key)
QID NAME Did
Address ID Address name
Did NAME

This is a foreign key association. Through did.

Team Address

Team ID Team Name
QID NAME
Team ID Address name
QID NAME

This is the primary key association, through the QID

Analysis: Team and address relationships. A team has an address and an address for a team (regardless of the 2 teams sharing an address).

Personal thinking: I think 1:1 is very interesting. If there is no other table associated with the Address table, the Address table can not, directly in the team table to add a field "address name." Because the team table and Address Table 1:1. That is, the team table and the "address name" 1:1. This is the table corresponding to the property.

5.1:n or N:1

People provinces

Person ID Id
Name NAME
Save ID Sid
Save ID Province name
Sid NAME

Analysis: A person belongs to a province, a province has many people.

Personal thinking: This situation has only one connection. The person is the child table, the province is the total table. The Pipe Union foreign key is placed in the child table. Why is it? This understanding: In the human table, a person only corresponds to a province ID, that is, a province. If the Union field is placed in the

In the provinces table, that is the table with a "Person id" field. The object of the table is a province with a "Person id", is a person. But it does not match the actual. The reality is: There are many people in a province.

6.n:n

Student Selection Course

School Number Name
Sid NAME
Course ID Course Name
XID NAME

Learning-Class

School Number Course Number
Sid XID

Analysis: A student has more than one course, and a class has multiple students.

Personal thinking: This many-to-many is also an association. You need to build an intermediate table that is the primary key of the associated table. Sid and Xid are the federated primary keys of the intermediate table (Learning-Class). There is no need to add any related words to the Student table and timetable.

database table Design 1

Related Article

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.