SQL Server Performance

does ident_current() work for uniqueidentifer also

Discussion in 'T-SQL Performance Tuning for Developers' started by halyal, Sep 30, 2009.

  1. halyal New Member

    I have a table where uniqueidentifer is the primary key and is
    generated with newid() in default value.
    How do I get the last value generated.

    Rajesh Halyal
  2. satya Moderator

    Welcome to the forums.
    IDENT_CURRENT returns the last identity value generated for a specific table in any session and any scope.

    @@IDENTITY returns the last identity value generated for any table in the current session, across all scopes.

    SCOPE_IDENTITY returns the last identity value generated for any table in the current session and the current scope.
  3. Adriaan New Member

    The functions being discussed all refer to an identity column, which uniqueidentifier is not.
    If your table has both an identity column and a uniqueidentifier column, you could retrieve the value from the uniqueidentifier column filtering on IDENT_CURRENT() or SCOPE_IDENTITY(), but it's not as if you can reasonably predict the next uniqueidentifier value based on the previous one.
  4. FrankKalis Moderator

    If the table has both a identity and a uniqueidentifier column, one might be inclined to question the design here.[:)]
    Anyway, one way on SQL Server 2005 and above would be to use the OUTPUT clause with the INSERT statement. Look up BOL for the syntax.
  5. Madhivanan Moderator

    If the version is less than 2005,
    Populate newid() to a variable and insert the value of that variable to the table
    Now you know the newid() that you lastly inserted

Share This Page