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 calleduserswith two columns,idandname, whereidis 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 theuserstable, with a unique UUID for theidcolumn andJohn Doefor thenamecolumn.
Helpful links
More of Mariadb
- How to get current year in Mariadb?
- How to check version of Mariadb?
- What type to use for a year in Mariadb?
- How to change wait_timeout in Mariadb?
- How to use the WITH clause in Mariadb?
- How to work with XML in Mariadb?
- Mariadb partitioning example
- How to use xtrabackup in Mariadb?
- How to use window functions in Mariadb?
- How to use variables in Mariadb?
See more codes...