简体   繁体   English

将h2数据库上的列的默认值更改为当前时间戳

[英]Change default value for column on h2 database to current timestamp

I have a h2 database with a schema that is auto generated via JPA/hibernate. 我有一个h2数据库,其架构是通过JPA / hibernate自动生成的。 Now I want to alter a not-null timestamp type column on the database to default to the current time. 现在我想将数据库上的非空timestamp类型列更改为默认为当前时间。

I actually use a trigger , and that works, but I'd like to know if there's a more elegant way to achieve this, something like (the following snippet doesn't work) 我实际上使用了一个触发器 ,这是有效的,但我想知道是否有更优雅的方法来实现这一点,类似(以下代码片段不起作用

ALTER TABLE my_table ALTER COLUMN my_column SET DEFAULT CURRENT_TIMESTAMP;

I looked at the documentation and tried some variants of the above "pseudo statement" but with now success. 我查看了文档并尝试了上述“伪语句”的一些变体,但现在已经成功。

看起来很近,你尝试过:

ALTER TABLE <table name> ALTER COLUMN <column name> SET DEFAULT CURRENT_TIMESTAMP

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM