When writing data, php is called one-to-one and one-to-many.

Source: Internet
Author: User
When php is writing data, it is called one-to-one and one-to-many. this is a tutorial. this guy tells me that when creating a table, sometimes one table is opposite to another table, sometimes this table needs to work on several tables, that is, one-to-one and one-to-many tables. for the specific reason, this guy will not talk about it, so someone else will talk about it!
What is this secret? what is one-to-one or one-to-many!
I understand that the relationship between tables is not one-to-one. what is one-to-many relationship?


Reply to discussion (solution)

Isn't the instructor and student tables one-to-many?
Isn't the subject table and student table many-to-many?

As for your textures, I don't know English. you didn't explain it. Not easy to say

Isn't the instructor and student tables one-to-many?
Isn't the subject table and student table many-to-many?

As for your textures, I don't know English. you didn't explain it. Not easy to say


What do you mean?

For example:
You have three tables.
Student table (student id student name)
Curriculum (course id course name)
Student id (course id Score)
Class table (class id student id)
Here, the class table and the student table are one-to-one. a class contains many students. in turn, they are multiple-to-one.
The course schedule here is a multi-to-one course. multiple students can select one or more courses.
As for the one-to-one relationship between professors and students, generally one professor corresponds to one student.

Simple
Three tables
Class table
Instructor table
Student table

Link
One class has multiple students
Therefore, the class table and student table are one-to-many.

One teacher has multiple students
Therefore, the instructor and student tables are one-to-many.

One class has multiple teachers
One teacher can teach multiple classes
Therefore, the class table and the instructor table are many-to-many.

Thank you for the two above. But there is still a small question: in this one-to-one, one-to-many, or many-to-many case, how can we see the role in mysql design? Or is there any constraint on this relationship?
Maybe I cannot express it accurately. Specifically, how can these relationships be expressed in SQL statements when writing SQL statements?

A few are your business concepts. they have nothing to do with the database itself and are naturally not reflected in SQL commands.

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.