可更新的主键
适用于 ✅ 开源版 ✅ 专业版 ✅ 企业版
在大多数数据库设计指南中,主键值被期望永远不会改变 - 这是规范化数据库必不可少的假设。
与往常一样,这些规则也有例外,用户可能希望在可更新记录功能中允许可更新的主键值(注意:任何值都可以通过普通的更新语句更新)。一个例子
AuthorRecord author = DSL.using(configuration) // This configuration will be attached to any record produced by the below query. .selectFrom(AUTHOR) .where(AUTHOR.ID.eq(1)) .fetchOne(); author.setId(2); author.store(); // The behaviour of this store call is governed by the updatablePrimaryKeys flag
上面的存储调用取决于 updatablePrimaryKeys
标志的值
-
false
(默认值):由于假设主键的不可变性,存储调用将创建一个具有新主键值的新记录(副本)。 -
true
:由于允许主键的可变性,存储调用会将主键值从1
更改为2
。
示例配置
Settings settings = new Settings() .withUpdatablePrimaryKeys(true); // Defaults to false
反馈
您对此页面有任何反馈吗? 我们很乐意听到您的反馈!