Plz solve this query
-
Hi I want to insert records as CustID & Custname in Customer table. custid Interger (autoincrement) Custname varchar2 & want to display last added record . Thnx
-
Hi I want to insert records as CustID & Custname in Customer table. custid Interger (autoincrement) Custname varchar2 & want to display last added record . Thnx
-
Care Career wrote:
I want to insert records as CustID & Custname in Customer table
Insert into Customer (Custname) values ('Value')
Care Career wrote:
& want to display last added record
select top 1 * from Customer order by CustID desc
I Love SQL
Blue_Boy wrote:
select top 1 * from Customer order by CustID desc
if you use a simple select like this, you could get the wrong record when by many users at the same time, instead you can use: select * from Customer where CustID = SCOPE_IDENTITY()
Alexei Rodriguez
-
Hi I want to insert records as CustID & Custname in Customer table. custid Interger (autoincrement) Custname varchar2 & want to display last added record . Thnx
-
@@IDENTITY returns last generated auto increment number with which you can get the last custid inserted into the table.
Regards KP
Krish - KP wrote:
@@IDENTITY returns last generated auto increment number
Yes, but for what table? If you have a large multi user database handling many transactions at once there is no guarantee that it will return the identity of the last row inserted in the scope your running in. It might return the identity for some other code running on some other table that just happens to be running at the same time as your code. You should use SCOPE_IDENTITY() to ensure that you get the identity of the last insert in your scope (and no one else's scope)
Upcoming events: * Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ... * Reading: Developer Day 5 Ready to Give up - Your help will be much appreciated. My website