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!
Mysql also supports the concept of User-defined variables, which allows passing of a value from one statement to another. A user-defined variable in Mysql is written as @var_name where, var_name is the name of the variable and can consist of alphanumeric characters, ., _, and $.
In MySQL there are three main data types: string, numeric, and date and time.
Boolean Data Type As a rule, they are used for logical operations. MySQL does not have a boolean (or bool) data type. Instead, it converts boolean values into integer data types (TINYINT).
User-defined data types (UDDT) in SQL Server Types A user-defined data type uses the existing data types with a set of constraints or rules. To create a UDDT, right-click on the user-defined data type folder and New user-defined data type.
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));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With