Does MySQL support table inheritance?

I have this code in PostgreSQL

CREATE TABLE first ( id serial, primary key(id) ); CREATE TABLE second (primary key(id)) INHERITS (first); 

What is equivalent code for MySQL?

+8
inheritance mysql postgresql
source share
1 answer

MySQL does not support table inheritance. The only way to get closer to functionality is to use a foreign key (which MySQL is not too good):

 CREATE TABLE first ( id serial, PRIMARY KEY (id) ); CREATE TABLE second ( parent integer REFERENCES first, PRIMARY KEY (parent) ); 

Obviously, you will have to change any views and queries from the "PostgreSQL inheritance version" to regular, multiply-connected queries.

+6
source share

All Articles