- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
In case of FOREIGN KEY constraint, what kind of relationship is there between MySQL parent and child tables?
152 Lectures 16 hours
87 Lectures 5.5 hours
The relationship between parent and child table is One-to-Many relationship. It can be understood with the example of two tables named ‘customer’ and ‘orders’. Here, ‘customer’ is the parent table and ‘orders’ is the child table. The relationship is one-to—many because a customer can have more than one order. It can be demonstrated by inserting the values in both the tables as follows −
mysql> Select * from Customer; +----+---------+ | id | name | +----+---------+ | 1 | Gaurav | | 2 | Raman | | 3 | Harshit | | 4 | Aarav | +----+---------+ 4 rows in set (0.00 sec) mysql> Select * from orders; +----------+----------+------+ | order_id | product | id | +----------+----------+------+ | 100 | Notebook | 1 | | 110 | Pen | 1 | | 120 | Book | 2 | | 130 | Charts | 2 | +----------+----------+------+ 4 rows in set (0.00 sec)
From the above result set it is clear that one customer can have many orders because customer having id = 1 is having two orders and customer having id = 2 is having two orders as well.
- MySQL error 1452 - Cannot add or a child row: a foreign key constraint fails
- Foreign key referencing of two DB2 tables
- MySQL error 1452 - Cannot add or update a child row: a foreign key constraint fails?
- What is the difference between MySQL PRIMARY KEY and UNIQUE constraint?
- How can we remove FOREIGN KEY constraint from a column of an existing MySQL table?
- Difference between Primary key and Foreign key in Database
- Difference Between Primary key and Foreign key in DBMS
- When are two tables connected with MySQL FOREIGN KEY then how can we say that the integrity of data is maintained in child table?
- How can we add a FOREIGN KEY constraint to the field of an existing MySQL table?
- Difference between Primary key and Foreign key in SQL Database
- Get a list of Foreign Key constraints in MySQL
- How can we assign FOREIGN KEY constraint on multiple columns?
- What kind of jobs are there in the IT sector?
- What is the relationship between CAPM and the Cost of Equity?
- What are Java parent and child classes in Java?