kwutchak
kwutchak

Reputation: 1022

Does MySQL support user defined data types

Is it possible to define (alias) a base data type in MySQL?

Currently I would like to define UUID as char(32), and then use UUID as the type throughout the schema definition. As we're prototyping at the moment, UUID is very likely to change - I'd like to ensure that this change is reflected consistently throughout the schema.

I'm thinking something like:

alias type UUID char(32);

Thanks in advance!

Upvotes: 13

Views: 9139

Answers (2)

Rock King Kirant
Rock King Kirant

Reputation: 59

well ENUM does the work until certain expectation of your custom data types, but i'm too hoping to look forward to this topic

Upvotes: -1

Castamos
Castamos

Reputation: 483

In this case a text preprocesor like M4 or any C-language preprocesor may be useful.

If you have the following in file tables.sql:

define(UUID, char(32))
create table mytable1 (my_uuid UUID);
create table mytable2 (my_uuid UUID);

Running

$ m4 tables.sql

you'll get:

create table mytable1 (my_uuid char(32));
create table mytable2 (my_uuid char(32));

Upvotes: 9

Related Questions