In this lesson, I will show you how to create a table with UUID PRIMARY KEY and how to insert UUID.
CREATE TABLE employee_by_uuid (
id uuid PRIMARY KEY,
first_name text,
last_name text
);
Insert Data:
INSERT INTO employee_by_uuid (id, first_name, last_name)
VALUES (uuid(), 'Jone', 'Doe');
Check Inserted Data:
SELECT * FROM employee_by_uuid;
CREATE TABLE employee_by_timeuuid (
id timeuuid PRIMARY KEY,
first_name text,
last_name text
);
Insert Data:
INSERT INTO employee_by_timeuuid (id, first_name, last_name)
VALUES (now(), 'Jone', 'Doe');
Check Inserted Data:
SELECT * FROM employee_by_timeuuid;
We will be able to sort by creation time of id if we use timeuuid.