I have this code in PostgreSQL
CREATE TABLE first (
id serial,
primary key(id)
);
CREATE TABLE second (primary key(id)) INHERITS (first);
What is the equivalent code for MySQL?
解决方案
MySQL does not support table inheritance. The only way to approximate the functionality is by using a foreign key (which MySQL isn't too good at either):
CREATE TABLE first (
id serial,
PRIMARY KEY (id)
);
CREATE TABLE second (
parent integer REFERENCES first,
PRIMARY KEY (parent)
);
Obviously, you'd have to change any views and queries from the PostgreSQL "inheritance version" to regular multi-relation queries.