transaction_id
1. TRANSACTION_ID Function
=======transaction_id
1. TRANSACTION_ID Function
>>>>>>> 9d19b1c8cb744c8e86d5c15b74d8b5f719ad62beThe TRANSACTION_ID function in H2 database is used to retrieve the unique identifier of the current transaction.
2. Syntax
The syntax for the TRANSACTION_ID function in H2 database is as follows:
TRANSACTION_ID()
Arguments
- None
Return
- The TRANSACTION_ID function returns a unique identifier (UUID) for the current transaction.
3. Notes
- The TRANSACTION_ID function in H2 database generates a new UUID for each transaction, ensuring uniqueness.
- This function is useful when you need to track or identify a specific transaction within your database.
- The generated UUID is a string of 36 characters in the form "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx".
4. Examples
Here are a few examples demonstrating the usage of the TRANSACTION_ID function in H2 database:
Example 1 - Retrieving the transaction ID:
SELECT TRANSACTION_ID() AS transaction_id;
Output:
transaction_id
--------------------------------------
d0f4b2f2-4e01-4d5a-8a1a-4f0c6a4e4eaf
Example 2 - Using the transaction ID in a query:
SELECT *
FROM transactions
WHERE transaction_id = TRANSACTION_ID();
Output:
-- Results based on your table schema and data
transaction_id | transaction_date | amount
-----------------------------------------+----------------------+-------
d0f4b2f2-4e01-4d5a-8a1a-4f0c6a4e4eaf | 2022-01-15 12:30:00 | 100.00
5. Related Functions
There are no directly related functions to the TRANSACTION_ID function. However, you may find the following functions useful for transaction-related operations:
- current_timestamp - Retrieve the current timestamp.
- COMMIT - Commit the current transaction.
- ROLLBACK - Rollback the current transaction.