In PostgreSQL, if I store a specific datatype (ex. an mail address
) in multiple columns across multiple tables, I could simply define a custom mail type with all constraints like so:
CREATE TYPE status_enum AS enum ('accepted', 'declined', 'awaiting');
CREATE DOMAIN mail_address
AS varchar(100) CHECK(value ~ '[A-Za-z0-9.]+@[A-Za-z0-9]+[.][A-Za-z]+');
and then use it like so:
CREATE TABLE user (
...
personal_email mail_address NOT NULL UNIQUE,
work_email mail_address NOT NULL UNIQUE,
status status_enum NOT NULL,
...
);
CREATE TABLE job (
...
status status_enum NOT NULL,
client_email mail_address NOT NULL UNIQUE,
...
);
I found out that MySQL is not object-relational database and therefore doesn't have custom datatype.
My question is:
How do people handle in MySQL reoccurring datatype in multiple column, in order to prevent copy-pasting identical constraints?