检索下一个可用的自动编号 [英] Retrieving next available AutoNumber

查看:59
本文介绍了检索下一个可用的自动编号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正忙于一个学校项目,在该项目中我从客户端查询基于服务器的数据库.其中一项要求是从数据库中检索下一个可用的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;

这篇关于检索下一个可用的自动编号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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