
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
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
- Related Articles
- Does Python support multiple inheritance?
- Does java support hybrid inheritance?
- Does Java support multiple inheritance? Why? How can we resolve this?
- Does Python support polymorphism?
- What information does SHOW TABLE DOES display in MySQL
- Does JavaScript support block scope?
- Does Selenium support Safari browser?
- How does Inheritance work in Ruby?
- Does HTML5 Canvas support Double Buffering?
- Does C++ support Variable Length Arrays
- Does Java support multi-dimensional Arrays?
- Does Selenium support headless browser testing?
- Why does Python Not Support Multithreading?
- How does class inheritance work in Python?
- Major Packages that support MySQL

Advertisements