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 1735
In SQL2000 use SCOPE_IDENTITY( ).
In SQL7.0 use @@IDENTITY.
See Books Online for details.
--
David Portas
SQL Server MVP
-- bi**********@ho tmail.com (Billy Cormic) wrote in message news:<dd******* *************** ****@posting.go ogle.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**********@ho tmail.com (Billy Cormic) wrote in message news:<dd******* *************** ****@posting.go ogle.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**********@ho tmail.com (Billy Cormic) wrote in message news:<dd******* *************** ****@posting.go ogle.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.goo gle.com>... bi**********@ho tmail.com (Billy Cormic) wrote in message news:<dd******* *************** ****@posting.go ogle.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.go ogle.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**********@ho tmail.com (Billy Cormic) wrote in message news:<dd******* *************** ****@posting.go ogle.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 tblSoftware
------------------- ------------------ ----------------------
PID PName PID* SID* SID SWName
--- ...
|
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 table from which I want to
delete has two foreign keys that references two other tables and it is
also referenced by another table. But this...
|
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 me what number
this last record is. so I can tell what number the next record inserted will
be.
How do I do this?
Thanks,
|
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 dataset.
My current app is using sqlClient and a typed
dataset that I created by exporting an xsd
|
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 = Dataset.tblMtTable.IndentityID
Simple but can't seem to do it in the formview.
Thanks
| |
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 hiddenfiekd:
<asp:HiddenField ID="HiddenField1" runat="server" Visible="false" />
In the code-behind:
Protected Sub DetailsView1_ItemInserted(ByVal...
|
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 within the grid, with the following through a button on a different tab page within the form, but it does not save changes to the database, just shows...
|
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 = oConn
cm.CommandText ="INSERT INTO t_test( blah blah")
|
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 is 2005 MS server.
on update/insert event for some table i hooked up the trigger that connects to linked server and updates the record in some DB....
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |