After inserting the value of the primary key identification field, I have used several methods.
Announcement @Tea table (id int identity primary key, some date datamate default demand ()) @t enter default values in SCOPE_IDENTITY () - Select back 1 @@ After entering the identity - return 1
, a table of identification is returning:
table # test (ID int identity, some day data item default demand ( )) To insert #include output. * Default value
What method is fair or better? Is the output method field safe?
The second code snippet was borrowed
It depends on you What are you trying to do ...
@@ identification
returns the final identity value produced on the connection, regardless of the table producing the price, and whether the statement Regardless of the scope of, the identity of @@ will return the final identification value recorded in the table in your current session. @@ identification is limited to the current session and it is not limited to the current scope. For example, if you have a trigger on a table that causes an identity in another table, you will get the identification that was created earlier, even if it was the trigger that made it.
SCOPE_IDENTITY ()
Provides value regardless of table, by the final identity value produced on connection and a statement in the same radius. SCOPE_IDENTITY () is similar to @@ identification, but it will also limit the value to your current radius. In other words, instead of an identity created by the trigger or user-defined function, this will return the clearly identifiable final identity value.
IDENT_CURRENT ()
Returns the final identity value produced in a table, whether the connection and the scope of the statement which produces the value. IDENT_CURRENT is limited to a specific table, but not from connection or region.
Comments
Post a Comment