mariadbHow to use UUID in Mariadb?
UUID stands for Universally Unique Identifier and is a 128-bit number used to identify information in computer systems. In MariaDB, UUIDs can be used to generate unique identifiers for rows in a table.
Example code
CREATE TABLE users (
id BINARY(16) PRIMARY KEY,
name VARCHAR(255)
);
INSERT INTO users (id, name) VALUES (UUID(), 'John Doe');
Output example
Query OK, 1 row affected (0.00 sec)
Code explanation
CREATE TABLE users (id BINARY(16) PRIMARY KEY, name VARCHAR(255));
- creates a table calledusers
with two columns,id
andname
, whereid
is a binary field of 16 bytes and is set as the primary key.INSERT INTO users (id, name) VALUES (UUID(), 'John Doe');
- inserts a new row into theusers
table, with a unique UUID for theid
column andJohn Doe
for thename
column.
Helpful links
More of Mariadb
- How to get current year in Mariadb?
- What type to use for a year in Mariadb?
- Mariadb partitioning example
- How to change wait_timeout in Mariadb?
- How to use variables in Mariadb?
- How to use xtrabackup in Mariadb?
- How to check version of Mariadb?
- How to use window functions in Mariadb?
- How to list users in Mariadb?
See more codes...