sqliteHow do I use a SQLite GUID?
A GUID (Globally Unique Identifier) is a 128-bit number used to uniquely identify records in a SQLite database. To use a GUID in SQLite, you must use the UUID
function. This function takes no parameters and returns a unique GUID.
Example code
SELECT UUID();
Example output:
2f7f3050-4a50-4f9e-9a9c-5e2b8d6f7c3f
The code above will generate a new GUID each time it is called. You can use this GUID to identify a record in a table. For example, to create a new record with a GUID in a table named users
:
INSERT INTO users (id, name) VALUES (UUID(), 'John Doe');
The code above will insert a new row into the users
table with a unique GUID as the id
and John Doe
as the name
.
Code explanation
SELECT UUID();
: This statement selects the UUID() function, which generates a new GUID.INSERT INTO users (id, name) VALUES (UUID(), 'John Doe');
: This statement inserts a new row into theusers
table with a unique GUID as theid
andJohn Doe
as thename
.
Helpful links
More of Sqlite
- How can SQLite and ZFS be used together for software development?
- How do I use the SQLite sequence feature?
- How do I use the SQLite ZIP VFS to compress a database?
- How can I use SQLite online?
- How do I use SQLite to retrieve data from a specific year?
- How do I use regular expressions to query a SQLite database?
- How to configure SQLite with XAMPP on Windows?
- How can I get the year from a date in SQLite?
- How can I use an upsert statement to update data in a SQLite database?
- How do I format a date in SQLite using the YYYYMMDD format?
See more codes...