How to Find a last inserted or updated query in a table

  • In ORACLE there is a keyword called "new" user can find the lasted inserted vale using the keyword.

    similarly how to find the last inserted row in the SQL2005.

    e.g if i have a table named "employee"

    with the fields as

    id - number

    name - varchar

    sex - varchar

    dob - date

    phno - number

    if a user want to find the what was the last "id", so that user can insert the next value.

    The "new" keyword in oracle does this in the "oracle", how it can be done with the sql2005.

    thank in advance..

    arasu.b

  • Hi,

    if you're looking for the equivalent of a sequence in Oracle, you would set up your ID column as an Identity column, for examply as an integer value, starting at zero, incrementing by one. When you insert into the table, you do not insert into this column - this is handled by the dbEngine. If you wish to use the ID value of the inserted row, use @@identity or scope_identity as appropriate to return the value of the ID column into a variable to use to return the value from the stored proc to the calling routine.

    hth

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply