
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Does MySQL Support Table Inheritance?
MySQL uses foreign key constraint instead of inheritance. MySQL does not support table inheritance.
You can achieve the same with the help of foreign key constraint. Let us create a table and use the foreign key constraint. The query to create the first table is as follows −
mysql> create table Parent_Table -> ( -> ParentId int, -> PRIMARY KEY(ParentId) -> ); Query OK, 0 rows affected (3.59 sec)
Now create the second table. The query to create the second table is as follows −
mysql> create table Child_Table -> ( -> ChildId int references Parent_Table, -> PRIMARY KEY(ChildId) -> ); Query OK, 0 rows affected (0.73 sec)
Now add the foreign key relationship between two tables. The query is as follows −
mysql> alter table Child_Table add constraint FK_Child Foreign key(ChildId) references Parent_Table(ParentId); Query OK, 0 rows affected (2.28 sec) Records: 0 Duplicates: 0 Warnings: 0
Advertisements