Home > Archive > MySQL ODBC Connector > April 2006 > Help Needed









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Help Needed
Bhanu Prakash

2006-04-04, 3:27 am

------ =_NextPart_000_0012_
01C65785.F71408B0
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit

Hi,

How can I get the current value of AUTO_INCREMENT field, as the
AUTO_INCREMENT field is a foreign key in some other table.please do mail
it to my mailed, its very urgent!!!!!

Thanks,
bhanu

"The pessimist may be right in the long run, but the optimist has a
better time during the trip."

G Bhanu Prakash (Senior Member Technical Staff)
Airtight Networks Pvt. Ltd.,
Airtight House, SN 149/1A,
off ITI Road,Aundh,
Pune 411007.
Mobile:9850764135

THE INFORMATION IN THIS EMAIL AND ANY ATTACHMENTS IS CONFIDENTIAL AND
INTENDED SOLELY FOR THE USE OF THE PERSON NAMED ABOVE. IF YOU ARE NOT
THE INTENDED RECIPIENT, OR HAVE OTHERWISE RECEIVED THIS EMAIL IN ERROR,
DO NOT READ, DISTRIBUTE, COPY OR OTHERWISE USE IT. IF YOU HAVE RECEIVED
THIS COMMUNICATION IN ERROR, PLEASE IMMEDIATELY NOTIFY THE SENDER BY
TELEPHONE OR EMAIL, AND DESTROY THIS MESSAGE AND ANY ATTACHMENTS. THANK
YOU."


------ =_NextPart_000_0012_
01C65785.F71408B0--


Gabriel PREDA

2006-04-04, 7:33 am

------ =_Part_32379_4612199
.1144139395063
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

If you do an INSERT and you generate an new number in an AUTO_INCREMENT
field the new value generated can be retrieved using:
*SELECT LAST_INSERT_ID();*

You are not required to retrieve into the application and then use it back
in another SQL statement... you can use user variables:
*SELECT @lastGenerated:=3DLA
ST_INSERT_ID();*

And then use: the variable in another query:
*INSERT INTO someTbl (id, someCol, somCol2) VALUES (NULL, @lastGenerated,
'OutsideValue');
*
Be warned that LAST_INSERT_ID() is functional only if you did not specified
the AUTO_INCREMENT field's value... only if you did not specified the
AUTO_INCREMENT field at all... or in the insert statement you used NULL or =
0
as a value... those values are considered "magic" by MySQL in case of an
AUTO_INCREMENT field.

Now part 2... if you didn't created an AUTO_INCREMENT field... and only wan=
t
to use the last value from that table:
Either you use a MAX() request:
*SELECT @lastGenerated:=3DMA
X(columnName) FROM tableName*
Or:
*SHOW TABLE STATUS LIKE 'tableName'*
and somewhere in the result is the AUTO_INCREMENT value.

Good luck !

--
Gabriel PREDA
Senior Web Developer

------ =_Part_32379_4612199
.1144139395063--
Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com