Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Plz solve this query

Plz solve this query

Scheduled Pinned Locked Moved Database
databasesales
5 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Care Career
    wrote on last edited by
    #1

    Hi I want to insert records as CustID & Custname in Customer table. custid Interger (autoincrement) Custname varchar2 & want to display last added record . Thnx

    B K 2 Replies Last reply
    0
    • C Care Career

      Hi I want to insert records as CustID & Custname in Customer table. custid Interger (autoincrement) Custname varchar2 & want to display last added record . Thnx

      B Offline
      B Offline
      Blue_Boy
      wrote on last edited by
      #2

      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

      A 1 Reply Last reply
      0
      • B Blue_Boy

        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

        A Offline
        A Offline
        AlexeiXX3
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • C Care Career

          Hi I want to insert records as CustID & Custname in Customer table. custid Interger (autoincrement) Custname varchar2 & want to display last added record . Thnx

          K Offline
          K Offline
          Krish KP
          wrote on last edited by
          #4

          @@IDENTITY returns last generated auto increment number with which you can get the last custid inserted into the table.

          Regards KP

          C 1 Reply Last reply
          0
          • K Krish KP

            @@IDENTITY returns last generated auto increment number with which you can get the last custid inserted into the table.

            Regards KP

            C Offline
            C Offline
            Colin Angus Mackay
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups