请考虑下表:
create table language (
id integer generated always as identity (START WITH 1, INCREMENT BY 1),
name long varchar,
constraint language_pk primary key (id)
);
Run Code Online (Sandbox Code Playgroud)
我以这种方式插入一个条目.
insert into language(name) values ('value');
Run Code Online (Sandbox Code Playgroud)
如何知道id创造了什么价值?只使用该name字段进行SELECT 无效,因为可能存在重复的条目.
通过纯SQL:
insert into language(name) values ('value');
SELECT IDENTITY_VAL_LOCAL();
Run Code Online (Sandbox Code Playgroud)
有关详细信息,请参阅手册:http://db.apache.org/derby/docs/10.7/ref/rrefidentityvallocal.html
从Java类(通过JDBC)执行此操作时,可以在使用approriate executeUpdate()方法"请求"它们之后使用getGeneratedKeys().
| 归档时间: |
|
| 查看次数: |
10509 次 |
| 最近记录: |