zoukankan      html  css  js  c++  java
  • 显示由 IDENT_CURRENT、@@IDENTITY 和 SCOPE_IDENTITY 返回的不同标识值

    以下示例将显示由 IDENT_CURRENT、@@IDENTITY 和 SCOPE_IDENTITY 返回的不同标识值。

     复制代码
    USE AdventureWorks;
    GO
    DROP TABLE t6;
    DROP TABLE t7;
    GO
    CREATE TABLE t6(id int IDENTITY);
    CREATE TABLE t7(id int IDENTITY(100,1));
    GO
    CREATE TRIGGER t6ins ON t6 FOR INSERT
    AS
    BEGIN
       INSERT t7 DEFAULT VALUES
    END;
    GO
    --End of trigger definition

    SELECT   * FROM t6;
    --id is empty.

    SELECT   * FROM t7;
    --ID is empty.

    --Do the following in Session 1
    INSERT t6 DEFAULT VALUES;
    SELECT @@IDENTITY;
    /*Returns the value 100. This was inserted by the trigger.*/

    SELECT SCOPE_IDENTITY();
    /* Returns the value 1. This was inserted by the
    INSERT statement two statements before this query.*/

    SELECT IDENT_CURRENT('t7');
    /* Returns value inserted into t7, that is in the trigger.*/

    SELECT IDENT_CURRENT('t6');
    /* Returns value inserted into t6. This was the INSERT statement four statements before this query.*/

    -- Do the following in Session 2.
    SELECT @@IDENTITY;
    /* Returns NULL because there has been no INSERT action
    up to this point in this session.*/

    SELECT SCOPE_IDENTITY();
    /* Returns NULL because there has been no INSERT action
    up to this point in this scope in this session.*/

    SELECT IDENT_CURRENT('t7');
    /* Returns the last value inserted into t7.*/
     

  • 相关阅读:
    委托和异步方法
    线程池_ThreadPool
    委托_deleget
    一步一步实现视频播放器client(二)
    mysql忘记password
    POJ 2456 Aggressive cows (二分 基础)
    Fragment小结
    Cocos2d-x粒子系统
    淘宝数据库OceanBase SQL编译器部分 源代码阅读--解析SQL语法树
    C与C++在形參的一点小差别
  • 原文地址:https://www.cnblogs.com/QDuck/p/1573225.html
Copyright © 2011-2022 走看看