Hello,
I would like do an insert into a table. The table has an auto
incrimenting unique int id. After I do the insert how do i get the
unique int id of the record that I just inserted? Is there a straight
forward way of accomplishing this?
Thanks,
Billy 6 1730
In SQL2000 use SCOPE_IDENTITY().
In SQL7.0 use @@IDENTITY.
See Books Online for details.
--
David Portas
SQL Server MVP
-- bi**********@hotmail.com (Billy Cormic) wrote in message news:<dd**************************@posting.google. com>... Hello, I would like do an insert into a table. The table has an auto incrimenting unique int id. After I do the insert how do i get the unique int id of the record that I just inserted? Is there a straight forward way of accomplishing this?
Thanks, Billy
Assuming that you're using MSSQL2000, then you can use the
SCOPE_IDENTITY() function.
Simon
Use the @@IDENTITY command. For eg.
declare temp int
insert into sometable .....
set temp = @@IDENTITY
Regards,
VS bi**********@hotmail.com (Billy Cormic) wrote in message news:<dd**************************@posting.google. com>... Hello, I would like do an insert into a table. The table has an auto incrimenting unique int id. After I do the insert how do i get the unique int id of the record that I just inserted? Is there a straight forward way of accomplishing this?
Thanks, Billy
Hi,
If you want to manually insert a value into the auto
incrementing id of the table set IDENTITY_INSERT to ON for the table
and then use the INSERT statement else simply supply the values to be
inserted without the autoid column in an INSERT statement. To retrieve
the newly inserted ID use @@identity or scope_identity()
Thanks,
JK bi**********@hotmail.com (Billy Cormic) wrote in message news:<dd**************************@posting.google. com>... Hello, I would like do an insert into a table. The table has an auto incrimenting unique int id. After I do the insert how do i get the unique int id of the record that I just inserted? Is there a straight forward way of accomplishing this?
Thanks, Billy
Thanks guys! The scope_identity() worked perfectly! sq*@hayes.ch (Simon Hayes) wrote in message news:<60*************************@posting.google.c om>... bi**********@hotmail.com (Billy Cormic) wrote in message news:<dd**************************@posting.google. com>... Hello, I would like do an insert into a table. The table has an auto incrimenting unique int id. After I do the insert how do i get the unique int id of the record that I just inserted? Is there a straight forward way of accomplishing this?
Thanks, Billy
Assuming that you're using MSSQL2000, then you can use the SCOPE_IDENTITY() function.
Simon
Thanks everyone for replying. The Scope_identity worked perfectly! ja**************@hotmail.com (JK) wrote in message news:<d5**************************@posting.google. com>... Hi, If you want to manually insert a value into the auto incrementing id of the table set IDENTITY_INSERT to ON for the table and then use the INSERT statement else simply supply the values to be inserted without the autoid column in an INSERT statement. To retrieve the newly inserted ID use @@identity or scope_identity() Thanks, JK
bi**********@hotmail.com (Billy Cormic) wrote in message news:<dd**************************@posting.google. com>... Hello, I would like do an insert into a table. The table has an auto incrimenting unique int id. After I do the insert how do i get the unique int id of the record that I just inserted? Is there a straight forward way of accomplishing this?
Thanks, Billy This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: PT |
last post by:
I got a problem. And thats.....
First of all, I got these three tables.
------------------- ------------------ ----------------------
tblPerson tblPersonSoftware ...
|
by: Robert Schneider |
last post by:
Hi to all,
I don't understand that: I try to delete a record via JDBC. But I always
get the error SQL7008 with the error code 3. It seems that this has
something to do with journaling, since the...
|
by: Mark |
last post by:
I'm using ASP.Net to accress a database, what I need to do is get the fields
out of the very last record in the db.
How do I do this?
Actually I'm after the primary key, titled 'AdID' it'll tell...
|
by: Jason L James |
last post by:
Hi all,
I recently wrote a vb.net app using oledb to
an access database. When I inserted new
rows in my datatable the identity column
was automatically created. This app used
an un-typed...
|
by: Craig |
last post by:
In ASP.NET 2.0 and the formview control how do you get the value of the
identity field of a newly inserted record?
In ASP.NET 1.1 after the new record was saved you just said
intNewIdentityID =...
|
by: Jan |
last post by:
Hello,
Just after the new record is inserted in the database using a Detailsview
control, i would like to display a short message "the record is inserted".
In the aspx file, i defined a...
|
by: nch1978 |
last post by:
I am new to programming and am sorry if this post is in the wrong area. I have a listbox bound to a table and a datagrid bound to another one with a connection through xml. I can change the data...
|
by: TimSki |
last post by:
Hi,
In my asp page I am inserting a record in to the sql server 2005 db as follows...
OpenDataConnection()
oConn.BeginTrans
set cm = CreateObject("ADODB.Command")
set cm.ActiveConnection =...
|
by: HotFrost |
last post by:
Hello everyone,
i am trying to work with linked servers...
The local server is the one used by UPS worldwide software (it is Microsoft SQL Server Desktop Engine, v 8.00.2050). The linked server...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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,...
|
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,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |