last_insert_guid

Return the most recently auto-generated guid value

Syntax

last_insert_guid()

Description

This function returns the value of the most recently auto-generated guid (globally universal identifier).

This function is designed for use with the insert statement so that after a row has been inserted for a table that contains a guid default auto primary key column, the rows for any referencing tables (i.e., those tables that have a foreign key that references it) can be inserted with the referencing column value being assigned to last_insert_guid().

Example

create database sales;
create table salesperson(
 	sale_id guid default auto primary key,
 	...
);
create table customer(
 	cust_id guid default auto primary key,
	name char(38),
 	sale_id guid not null 
 		references salesperson 
 			on update cascade 
 			on delete restrict
);
commit;
insert into salesperson values , "Haskell, Eddie", "M", date "1943-07-01",
 	current_date(), 0.0, "SEA", null;
insert into customer values , "Cleaver, Theodore", last_insert_guid();

commit;