• <tfoot id='JDXVM'></tfoot>
    <i id='JDXVM'><tr id='JDXVM'><dt id='JDXVM'><q id='JDXVM'><span id='JDXVM'><b id='JDXVM'><form id='JDXVM'><ins id='JDXVM'></ins><ul id='JDXVM'></ul><sub id='JDXVM'></sub></form><legend id='JDXVM'></legend><bdo id='JDXVM'><pre id='JDXVM'><center id='JDXVM'></center></pre></bdo></b><th id='JDXVM'></th></span></q></dt></tr></i><div id='JDXVM'><tfoot id='JDXVM'></tfoot><dl id='JDXVM'><fieldset id='JDXVM'></fieldset></dl></div>
  • <legend id='JDXVM'><style id='JDXVM'><dir id='JDXVM'><q id='JDXVM'></q></dir></style></legend>

      <small id='JDXVM'></small><noframes id='JDXVM'>

        • <bdo id='JDXVM'></bdo><ul id='JDXVM'></ul>

        Scope_Identity()、Identity()、@@Identity 和 Ident_Current() 之间有

        What is the difference between Scope_Identity(), Identity(), @@Identity, and Ident_Current()?(Scope_Identity()、Identity()、@@Identity 和 Ident_Current() 之间有什么区别?)

            1. <small id='rLUbU'></small><noframes id='rLUbU'>

                  <bdo id='rLUbU'></bdo><ul id='rLUbU'></ul>
                  <i id='rLUbU'><tr id='rLUbU'><dt id='rLUbU'><q id='rLUbU'><span id='rLUbU'><b id='rLUbU'><form id='rLUbU'><ins id='rLUbU'></ins><ul id='rLUbU'></ul><sub id='rLUbU'></sub></form><legend id='rLUbU'></legend><bdo id='rLUbU'><pre id='rLUbU'><center id='rLUbU'></center></pre></bdo></b><th id='rLUbU'></th></span></q></dt></tr></i><div id='rLUbU'><tfoot id='rLUbU'></tfoot><dl id='rLUbU'><fieldset id='rLUbU'></fieldset></dl></div>
                • <legend id='rLUbU'><style id='rLUbU'><dir id='rLUbU'><q id='rLUbU'></q></dir></style></legend>
                • <tfoot id='rLUbU'></tfoot>

                    <tbody id='rLUbU'></tbody>
                  本文介绍了Scope_Identity()、Identity()、@@Identity 和 Ident_Current() 之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我知道 Scope_Identity()Identity()@@IdentityIdent_Current() 所有获取标识列的值,但我很想知道其中的区别.

                  I know Scope_Identity(), Identity(), @@Identity, and Ident_Current() all get the value of the identity column, but I would love to know the difference.

                  我遇到的部分争议是,它们所指的适用于上述这些功能的范围是什么意思?

                  Part of the controversy I'm having is what do they mean by scope as applied to these functions above?

                  我也喜欢使用它们的不同场景的简单示例?

                  I would also love a simple example of different scenarios of using them?

                  推荐答案

                  • @@identity 函数返回在同一会话中创建的最后一个身份.
                  • scope_identity() 函数返回在同一会话和同一范围内创建的最后一个身份.
                  • ident_current(name) 返回为任何会话中的特定表或视图创建的最后一个标识.
                  • identity() 函数不用于获取身份,而是用于在 select...into 查询中创建身份.
                    • The @@identity function returns the last identity created in the same session.
                    • The scope_identity() function returns the last identity created in the same session and the same scope.
                    • The ident_current(name) returns the last identity created for a specific table or view in any session.
                    • The identity() function is not used to get an identity, it's used to create an identity in a select...into query.
                    • 会话是数据库连接.作用域是当前查询或当前存储过程.

                      The session is the database connection. The scope is the current query or the current stored procedure.

                      scope_identity()@@identity 函数不同的情况是,如果您在表上有触发器.如果您有一个插入记录的查询,导致触发器在某处插入另一条记录,scope_identity() 函数将返回查询创建的标识,而 @@identity 函数将返回触发器创建的标识.

                      A situation where the scope_identity() and the @@identity functions differ, is if you have a trigger on the table. If you have a query that inserts a record, causing the trigger to insert another record somewhere, the scope_identity() function will return the identity created by the query, while the @@identity function will return the identity created by the trigger.

                      因此,通常您会使用 scope_identity() 函数.

                      So, normally you would use the scope_identity() function.

                      这篇关于Scope_Identity()、Identity()、@@Identity 和 Ident_Current() 之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                      本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Select n random rows from SQL Server table(从 SQL Server 表中随机选择 n 行)
                  SQL query to select dates between two dates(用于选择两个日期之间的日期的 SQL 查询)
                  How can I delete using INNER JOIN with SQL Server?(如何在 SQL Server 中使用 INNER JOIN 进行删除?)
                  Table Naming Dilemma: Singular vs. Plural Names(表命名困境:单数与复数名称)
                  INSERT statement conflicted with the FOREIGN KEY constraint - SQL Server(INSERT 语句与 FOREIGN KEY 约束冲突 - SQL Server)
                  How ROWNUM works in pagination query?(ROWNUM 如何在分页查询中工作?)

                  <i id='sW766'><tr id='sW766'><dt id='sW766'><q id='sW766'><span id='sW766'><b id='sW766'><form id='sW766'><ins id='sW766'></ins><ul id='sW766'></ul><sub id='sW766'></sub></form><legend id='sW766'></legend><bdo id='sW766'><pre id='sW766'><center id='sW766'></center></pre></bdo></b><th id='sW766'></th></span></q></dt></tr></i><div id='sW766'><tfoot id='sW766'></tfoot><dl id='sW766'><fieldset id='sW766'></fieldset></dl></div>
                      <tbody id='sW766'></tbody>
                    <legend id='sW766'><style id='sW766'><dir id='sW766'><q id='sW766'></q></dir></style></legend>

                    <tfoot id='sW766'></tfoot>

                      <bdo id='sW766'></bdo><ul id='sW766'></ul>

                            <small id='sW766'></small><noframes id='sW766'>