473,289 Members | 1,961 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,289 software developers and data experts.

read out an AUTO_INCREMENT-ed value

Hello,

The first column of my table is AUTO_INCREMENT.
I fill my table with 5 records with a blanco value in their first
field.
The first column of my table will then hold the values 1,2,3,4,5
(top>down).

Then I erase those 5. Then I add a new record with a blanco first
value. It will get number 6.

My problem in this scenario:
I want to read out this number 6 before I will insert that record. Is
that possible?

Thanks,
Bart
Jul 19 '05 #1
9 3302
Bart Van der Donck wrote:
My problem in this scenario:
I want to read out this number 6 before I will insert that record. Is
that possible?


May I ask why? I can't imagine any good reason for that.
Jul 19 '05 #2
Bart Van der Donck wrote:
My problem in this scenario:
I want to read out this number 6 before I will insert that record. Is
that possible?


May I ask why? I can't imagine any good reason for that.
Jul 19 '05 #3
Bart Van der Donck wrote:
My problem in this scenario:
I want to read out this number 6 before I will insert that record. Is
that possible?


May I ask why? I can't imagine any good reason for that.
Jul 19 '05 #4
Aggro <sp**********@yahoo.com> wrote in message news:<jb***************@read3.inet.fi>...
Bart Van der Donck wrote:
My problem in this scenario:
I want to read out this number 6 before I will insert that record. Is
that possible?


May I ask why? I can't imagine any good reason for that.


I am working with binary objects that I store in a directory. I let
the application take the ID of a row, then put a file extension behind
this ID, and finally put a fixed directory path before the ID. That
way the application knows which object belongs to which row in my
table.

Now when adding new records, I have to know though what the name of
the object must be. Obviously the same as the ID of my row that I am
about to insert. So that the application can find it back later.

So basically I was hoping for something like:
"SELECT CURRENT_AUTO_INCREMENT_NUMBER FROM mytable"

or even better, something like:
"INSERT INTO mytable VALUES ('','data1','data2') RETURN
AUTO_INCREMENT"
and that it would return the value that was inserted in the first
field (that was an AUTO_INCREMENT)

regards
Bart
Jul 19 '05 #5
Aggro <sp**********@yahoo.com> wrote in message news:<jb***************@read3.inet.fi>...
Bart Van der Donck wrote:
My problem in this scenario:
I want to read out this number 6 before I will insert that record. Is
that possible?


May I ask why? I can't imagine any good reason for that.


I am working with binary objects that I store in a directory. I let
the application take the ID of a row, then put a file extension behind
this ID, and finally put a fixed directory path before the ID. That
way the application knows which object belongs to which row in my
table.

Now when adding new records, I have to know though what the name of
the object must be. Obviously the same as the ID of my row that I am
about to insert. So that the application can find it back later.

So basically I was hoping for something like:
"SELECT CURRENT_AUTO_INCREMENT_NUMBER FROM mytable"

or even better, something like:
"INSERT INTO mytable VALUES ('','data1','data2') RETURN
AUTO_INCREMENT"
and that it would return the value that was inserted in the first
field (that was an AUTO_INCREMENT)

regards
Bart
Jul 19 '05 #6
Aggro <sp**********@yahoo.com> wrote in message news:<jb***************@read3.inet.fi>...
Bart Van der Donck wrote:
My problem in this scenario:
I want to read out this number 6 before I will insert that record. Is
that possible?


May I ask why? I can't imagine any good reason for that.


I am working with binary objects that I store in a directory. I let
the application take the ID of a row, then put a file extension behind
this ID, and finally put a fixed directory path before the ID. That
way the application knows which object belongs to which row in my
table.

Now when adding new records, I have to know though what the name of
the object must be. Obviously the same as the ID of my row that I am
about to insert. So that the application can find it back later.

So basically I was hoping for something like:
"SELECT CURRENT_AUTO_INCREMENT_NUMBER FROM mytable"

or even better, something like:
"INSERT INTO mytable VALUES ('','data1','data2') RETURN
AUTO_INCREMENT"
and that it would return the value that was inserted in the first
field (that was an AUTO_INCREMENT)

regards
Bart
Jul 19 '05 #7
Bart Van der Donck wrote:
or even better, something like:
"INSERT INTO mytable VALUES ('','data1','data2') RETURN
AUTO_INCREMENT"
and that it would return the value that was inserted in the first
field (that was an AUTO_INCREMENT)


Atleast in PHP, C and C++ API for MySQL have a function that will return
the last inserted auto_increment value. You didn't mention which
language you are using so it's hard to give any specific instructions.

But usually there is always a method that will return the auto_increment
id value for previously inserted row. If there isn't you can get it by
committing a second query to database and using LAST_INSERT_ID() SQL
function.

"You can retrieve the most recent AUTO_INCREMENT value with the
LAST_INSERT_ID() SQL function or the mysql_insert_id() C API function.
These functions are connection-specific, so their return value is not
affected by another connection also doing inserts."

More information:
http://www.mysql.com/doc/en/example-AUTO_INCREMENT.html
Jul 19 '05 #8
Bart Van der Donck wrote:
or even better, something like:
"INSERT INTO mytable VALUES ('','data1','data2') RETURN
AUTO_INCREMENT"
and that it would return the value that was inserted in the first
field (that was an AUTO_INCREMENT)


Atleast in PHP, C and C++ API for MySQL have a function that will return
the last inserted auto_increment value. You didn't mention which
language you are using so it's hard to give any specific instructions.

But usually there is always a method that will return the auto_increment
id value for previously inserted row. If there isn't you can get it by
committing a second query to database and using LAST_INSERT_ID() SQL
function.

"You can retrieve the most recent AUTO_INCREMENT value with the
LAST_INSERT_ID() SQL function or the mysql_insert_id() C API function.
These functions are connection-specific, so their return value is not
affected by another connection also doing inserts."

More information:
http://www.mysql.com/doc/en/example-AUTO_INCREMENT.html
Jul 19 '05 #9
Bart Van der Donck wrote:
or even better, something like:
"INSERT INTO mytable VALUES ('','data1','data2') RETURN
AUTO_INCREMENT"
and that it would return the value that was inserted in the first
field (that was an AUTO_INCREMENT)


Atleast in PHP, C and C++ API for MySQL have a function that will return
the last inserted auto_increment value. You didn't mention which
language you are using so it's hard to give any specific instructions.

But usually there is always a method that will return the auto_increment
id value for previously inserted row. If there isn't you can get it by
committing a second query to database and using LAST_INSERT_ID() SQL
function.

"You can retrieve the most recent AUTO_INCREMENT value with the
LAST_INSERT_ID() SQL function or the mysql_insert_id() C API function.
These functions are connection-specific, so their return value is not
affected by another connection also doing inserts."

More information:
http://www.mysql.com/doc/en/example-AUTO_INCREMENT.html
Jul 19 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Pjotr Wedersteers | last post by:
I have a table with quiz questions. Each question has a unique ID, based on an auto_increment field. Now I've discovered that with deleting rows from the table the deleted ID's are not reissued....
0
by: FatBlokeOnBikepins | last post by:
.. Can I auto_increment in multiples of 10s or 20s or.... ?
2
by: Ittay Freiman | last post by:
i cannot set auto_increment to start from anything other than 1: mysql> create table test (id int unsigned not null auto_increment primary key); mysql> alter table test auto_increment=2; ...
2
by: Nico v. Rossum | last post by:
Hi * How can reset a auto_incremet collumn so it starts from 1 TIA
4
by: Dark Matt | last post by:
I'm looking at setting up two mysql servers in replication with both being masters. The most obvious snag in this scenario is auto_increment, as disconnections between servers could allow user...
2
by: Krista | last post by:
Hi everybody, i am doing web application implemented with php and mysql. i want to create a table in the database with auto increment eg CREATE TABLE $TableName_2( ID int unsigned auto_increment...
2
by: hjyn | last post by:
Hi, how can I add char to auto_increment? For example, the auto_increment is for integer, I want to add a character at the front of that number. Ex: >create table abs (UserID INT(3) NOT NULL...
1
by: Phil Latio | last post by:
Newbie questions here... Reading the MySQL manual regarding InnoDB databases, can someone confirm that: 1. if the server is rebooted, AUTO_INCREMENT reverts back to 1? 2. what happens if the...
0
by: whitemoss | last post by:
Hi All, I had written a code to read a file and insert it's contents to the database. Since I will receive 3 files every hour, so, this program should read those files and insert the contents...
1
by: mostafijur | last post by:
Hello, My database table containing a column name P_ID Field Extra = P_ID, Type = int(11), Null = NO, Key = PRI, Default = NULL, Extra = auto_increment
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.