Results 1 to 3 of 3

Thread: [RESOLVED] Scope_Identity in SQL Server

  1. #1

    Thread Starter
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Resolved [RESOLVED] Scope_Identity in SQL Server

    OK this may be an odd question but here goes.


    We are looking to pull one table out of our current database (this holds attachments mostly Word Docs) and place it into a supporting database.

    All the procedures and views are simple to modify of course just prefix the new database name in front of the table. My question suround the Insert proc. We return the newly inserted identity value use Scope_Identity() function currently, with the move of the table into a new database I don't think that will work (correct?). If I create the proc_Insert in the new DB can I return the Value back to a modified procedure in the orginal DB as an output parameter?
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  2. #2
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,957

    Re: Scope_Identity in SQL Server

    All scope_identity does is return the last value of an identity column. Provided you've set the seed to an apropriate value the new values should increase from that point and scope_identity will still return the correct value.

    When we do this we usually increase the seed to an arbitrarily higher value than the highest existing identity because it makes it easy to spot wich records were inserted after the migration. eg if the seed has reaced 12,345 we'll set the seed to 20,000.
    The best argument against democracy is a five minute conversation with the average voter - Winston Churchill

    Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd

  3. #3

    Thread Starter
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: Scope_Identity in SQL Server

    OK thanks.... So it will pick cross databases that is what I was woundering.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width