473,466 Members | 1,456 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 3307
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
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.