Professional Web Applications Themes

Identities - Microsoft SQL / MS SQL Server

Mr. J. (ab.com) writes:  SELECT scope_identity()   You could use DBCC CHECKIDENT, but this is not something you would use in application code. If you have these needs you should probably not use IDENTITY, but roll your own. -- Erland Sommarskog, SQL Server MVP, se Books Online for SQL Server SP3 at http://www.microsoft.com/sql/techinfo/productdoc/2000/books.asp...

  1. #1

    Default Re: Identities

    Mr. J. (ab.com) writes: 

    SELECT scope_identity()
     

    You could use DBCC CHECKIDENT, but this is not something you would use in
    application code. If you have these needs you should probably not use
    IDENTITY, but roll your own.


    --
    Erland Sommarskog, SQL Server MVP, se

    Books Online for SQL Server SP3 at
    http://www.microsoft.com/sql/techinfo/productdoc/2000/books.asp
    Erland Guest

  2. #2

    Default Identities

    Hello,
    In SQL-Server :
    1) How can I get the current identity number of a table after I insert a
    record (if the primary key is identity) ?
    2) What SQL-command is for changing the Identity current number (so, if I
    insert another record, I'll start with another sequence number) ?

    Thanks :)



    Mr. Guest

  3. #3

    Default Re: Identities

    Hello,

    Thanks ...
    someone else have told me about another solution :
    identity.
    Is identity the same thing as scope_identity() ?

    Thanks :)
    "Erland Sommarskog" <se> wrote in message
    news:0.0.1... 
    >
    > SELECT scope_identity()
    > [/ref]

    >
    > You could use DBCC CHECKIDENT, but this is not something you would use in
    > application code. If you have these needs you should probably not use
    > IDENTITY, but roll your own.
    >
    >
    > --
    > Erland Sommarskog, SQL Server MVP, se
    >
    > Books Online for SQL Server SP3 at
    > http://www.microsoft.com/sql/techinfo/productdoc/2000/books.asp[/ref]


    Mr. Guest

  4. #4

    Default Re: Identities

    Mr. J. (ab.com) writes: 

    Almost. The difference is that identity returns the most recently
    created identity value, while scope_identity() returns the most
    recently idetnity value in the current scope (= stored procedure, trigger,
    loose block of SQL statements). identity can give nasty surprises if
    you insert into a table which have a trigger and that trigger inserts
    into a second table with the identity property.


    --
    Erland Sommarskog, SQL Server MVP, se

    Books Online for SQL Server SP3 at
    http://www.microsoft.com/sql/techinfo/productdoc/2000/books.asp
    Erland Guest

Similar Threads

  1. lack of understanding of principals, identities, and context
    By Teemu Keiski in forum ASP.NET Security
    Replies: 4
    Last Post: August 21st, 06:40 PM
  2. extra identities
    By Paulette Harper in forum Windows XP/2000/ME
    Replies: 2
    Last Post: July 19th, 02:45 PM
  3. XP Outlook Express identities
    By James in forum Windows XP/2000/ME
    Replies: 0
    Last Post: July 3rd, 06:17 PM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139