I have this three tables:
CREATE TABLE userTypeA
(
id VARCHAR (256) PRIMARY KEY,
nickname VARCHAR (256) NOT NULL,
password VARCHAR(70) NOT NULL DEFAULT '123456'
--AND MORE OTHER ATTRIBUTTES DIFFERENT FROM OTHER USERTYPES
);
CREATE TABLE userTypeB
(
id VARCHAR (256) PRIMARY KEY ,
nickname VARCHAR (256) NOT NULL,
password VARCHAR(70) NOT NULL DEFAULT '123456'
--AND MORE OTHER ATTRIBUTTES DIFFERENT FROM OTHER USERTYPES
);
CREATE TABLE userTypeC
(
id VARCHAR (256) PRIMARY KEY ,
nickname VARCHAR (256) NOT NULL,
password VARCHAR(70) NOT NULL DEFAULT '123456'
--AND MORE OTHER ATTRIBUTTES DIFFERENT FROM OTHER USERTYPES
);
Now, my idea was creating a table which has a foreign key that can reference the id of one of the three tables (userTypeA, userTypeB, userTypeC). In occasions it will reference table userTypeA, on other occasions it will reference table userTypeB and in others userTypeC. I tried this, but it seems to fail:
CREATE TABLE account
(
account_id VARCHAR (256),
user_id VARCHAR (256),
PRIMARY KEY (account_id),
CONSTRAINT accounts_users_fk1 FOREIGN KEY (user_id) REFERENCES userTypeA (id),
CONSTRAINT accounts_users_fk2 FOREIGN KEY (user_id) REFERENCES userTypeB (id),
CONSTRAINT accounts_users_fk3 FOREIGN KEY (user_id) REFERENCES userTypeC (id),
);
I've been looking for some examples but none looked like mine. Do you know any way to be able to reference one of the three tables with a single foreign key, or should I create different tables and structure them differently?