问题描述
我正忙于一个学校项目,在该项目中我从客户端查询基于服务器的数据库.其中一项要求是从数据库中检索下一个可用的AutoNumber
.
I am busy with a school project where I query a database based on a server from a client. One of the requirements is to retrieve the next available AutoNumber
from the database.
检索下一个可用的Autonumber
的 SQL 查询是什么?可以这样做吗?
What would the SQL query be to retrieve the next available Autonumber
? Is it possible to do this?
推荐答案
这取决于 RDBMS 的风格.MariaDB (MySQL) 有 LAST_INSERT_ID() 函数,它为您提供 AUTO_INCREMENT 字段的最后一个值.
It depends on the flavor of the RDBMS. MariaDB (MySQL) have LAST_INSERT_ID() function which gives you the last value of an AUTO_INCREMENT field.
支持序列的数据库(例如 Ingres)允许您使用以下内容获取下一个值:
Databases that support sequences (say Ingres) allow you to get next value with something like:
SELECT NEXT VALUE FOR some_sequence;
或
SELECT some_sequence.NEXTVAL;
这篇关于检索下一个可用的自动编号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!