默认情况下,为H2数据库引擎中UUID类型的列上的每一行生成UUID值 [英] Generate UUID values by default for each row on column of UUID type in H2 Database Engine

查看:245
本文介绍了默认情况下,为H2数据库引擎中UUID类型的列上的每一行生成UUID值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

H2数据库中,该表的列为 UUID数据类型,我们如何指定希望H2生成 UUID值默认情况下,当 INSERT 忽略该值时

In the H2 database, on a table with a column of UUID data type, how do we specify that we want H2 to generate a UUID value by default when an INSERT omits that field?

我知道如何生成UUID
我已经阅读了问题, 如何在h2数据库中插入特定的UUID?

I know how to generate a UUID. I have read the Question, How to insert a specific UUID in h2 database?.

我的问题是关于如何让H2代表我生成UUID值。

My question is about how to ask H2 to generate the UUID value on my behalf.

推荐答案

您可以使用内置函数 RANDOM_UUID ()

You can use built-in function RANDOM_UUID():

create table test(id int primary key, data uuid default random_uuid());
insert into test(id) values(1);
select * from test;

请注意,使用UUID(或任何其他随机生成的数据)作为主键会提高性能如果行数超过几百万,就会出现问题(通常是关系数据库,而不仅仅是H2)。

Note that using the UUID (or any other randomly generated data) as the primary key will result in performance problems if there are more than a few million rows (with relational databases in general, not just with H2).

这篇关于默认情况下,为H2数据库引擎中UUID类型的列上的每一行生成UUID值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆