MariaDB SYS_GUID SQL Function - GUID (Global Unique Identifier)
SYS_GUID
Syntax:
SYS_GUID()
Return value:
CHAR
Function type:
Miscellaneous function
Function Description
The SYS_GUID() function returns a 16-byte GUID (Globally Unique Identifier) as a hexadecimal value with 32 characters.
The function works similar to the UUID() function, but without the separator.
The feature was introduced in MariaDB from version 10.7 for Oracle compatibility. It doesn't exist in MySQL.
SQL Examples for the SYS_GUID function
1 2 3
SELECTSYS_GUID();
sys_guid()
varchar(32) BINARY
36aac8ffd63211ed9a480800275588ea
Example of creating a replacement function for SYS_GUID() in MySQL
1 2 3 4 5 6 7 8 910111213141516
/* Use MULTI-QUERY-Option in myway SQL manager */DROPFUNCTIONIFEXISTSSYS_GUID;CREATEFUNCTIONSYS_GUID()RETURNSvarchar(32)BEGINreturnreplace(uuid(), '-', '');END;SELECTSYS_GUID();
sys_guid()
varchar(32) BINARY
18acee4ade8e11eda01c80ee73e9b513
The examples were created with the MyWAY SQL manager: Download
How to use the SYS_GUID() function in MySQL and MariaDB databases
In MySQL and MariaDB databases the SYS_GUID() function is used to generate a new Globally Unique Identifier: GUID value. The function can be used directly in a SQL statement or within a SQL query, requires no arguments, and returns a string of hexadecimal characters representing a unique identifier that can be used as a primary key or for other identification purposes.
GUIDs are used as unique identifiers in distributed systems or when generating keys that must be globally unique. This can be used to generate unique primary keys for tables, especially in distributed environments or when data from multiple sources needs to be merged. In data synchronization and data replication, GUIDs are useful to ensure uniqueness and avoid conflicts when synchronizing or replicating data across multiple databases or systems.