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 yesterday's date in Mariadb?
- How to get current year in Mariadb?
- What type to use for a year in Mariadb?
- How to work with XML in Mariadb?
- How to use variables in Mariadb?
- How to use the WITH clause in Mariadb?
- How to list available engines in Mariadb?
- How to view Mariadb error log?
- How to use XA transactions in Mariadb?
- How to check version of Mariadb?
See more codes...