MySQL是否支持用户定义的数据类型 [英] Does MySQL support user defined data types

查看:299
本文介绍了MySQL是否支持用户定义的数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在MySQL中定义(别名)基本数据类型?

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

当前,我想将UU​​ID定义为char(32),然后在整个架构定义中使用UUID作为类型.目前,我们正在制作原型,UUID很有可能会发生变化-我想确保这种变化在整个架构中始终如一地体现出来.

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.

我在想类似的东西:

别名类型为UUID char(32);

alias type UUID char(32);

提前谢谢!

推荐答案

在这种情况下,像M4这样的文本预处理程序或任何C语言预处理程序都可能有用.

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

如果文件table.sql中包含以下内容:

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);

运行

$ m4 tables.sql

您将获得:

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

这篇关于MySQL是否支持用户定义的数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆