`

IDENT_CURRENT

 
阅读更多

IDENT_CURRENT

返回为任何会话和任何作用域中的指定表最后生成的标识值。

语法

IDENT_CURRENT('table_name')

参数

table_name

是将要返回其标识值的表的名称。table_name 的数据类型为 varchar,没有默认值。

返回类型

sql_variant

注释

IDENT_CURRENT 类似于 Microsoft® SQL Server™ 2000 标识函数 SCOPE_IDENTITY 和 @@IDENTITY。这三个函数都返回最后生成的标识值。但是,它们在定义"最后"的作用域和会话上不同。

  • IDENT_CURRENT 返回为任何会话和任何作用域中的特定表最后生成的标识值。

  • @@IDENTITY 返回为当前会话的所有作用域中的任何表最后生成的标识值。

  • SCOPE_IDENTITY 返回为当前会话和当前作用域中的任何表最后生成的标识值。
示例

下面的示例说明由 IDENT_CURRENT、@@IDENTITY 和 SCOPE_IDENTITY 返回的不同的标识值。

USE pubs
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, which was inserted by the trigger.*/
SELECT SCOPE_IDENTITY()   
/* Returns the value 1, which was inserted by the INSERT stmt 2 statements before this query.*/
SELECT IDENT_CURRENT('t7')
/* Returns value inserted into t7, i.e. in the trigger.*/
SELECT IDENT_CURRENT('t6')
/* Returns value inserted into t6, which was the INSERT statement 4 stmts before this query.*/
-- Do the following in Session 2
SELECT @@IDENTITY
/* Returns NULL since there has been no INSERT action so far in this session.*/
SELECT SCOPE_IDENTITY()
/* Returns NULL since there has been no INSERT action so far in this scope in this session.*/
SELECT IDENT_CURRENT('t7')
/* Returns the last value inserted into t7.*/

分享到:
评论

相关推荐

    数据库练习(知识点蛮多)

    insert into cj_t values(IDENT_CURRENT('xs_t'),3,66,1) insert into cj_t values(IDENT_CURRENT('xs_t'),4,75,1) insert into cj_t values(IDENT_CURRENT('xs_t'),5,73,1) insert into xs_t values('1','Tom','...

    得到自增列的下一个会插入的id

    Select so.name Table_name, –表名字 sc.name Iden_Column_name, –自增字段名字 ident_current(so.name) curr_value, –自增字段当前值 ident_incr(so.name) incr_value, –自增字段增长值 ident_seed(so.name) ...

    gc2145_parrotv1.1_r16m_验证完成_20170523_1408没有外层目录.7z

    全志R16的android4.4.2平台点亮gc2145(evb30) 版本:V1.1 1、配置ov2640在android层配置的分辨率为vga(预览/拍照/录像) 注意:系统自带的快拍APP就在这里查找分辨率参数发送到camera的HAL层。...

    FastReport_6.6.15_VCL_Enterprise_Sources.rar

    Current version ---------------------------- + Fixed preview tabs in custom preview control + Added Processing for TfrxSysMemoView [6.6.1 - 6.6.12] + [Lazarus] Added LazChart RTTI modules - Fixed bug ...

    keil3_full

    选择Update Current Installation升级安装,将可以保持原来的序列号,不必再次输入 3.选择Full安装,Next->Yes(接受版权信息)->选择安装目录->Next->输入序列号、姓名、公司 等,除了序列号以外,都随意,可以如实...

    第13章 多线程与多进程编程.pptx

    * current_thread() 方法返回当前 Thread 对象。 * get_ident() 方法返回当前线程的线程标识符。 * enumerate() 方法返回当前处于 alive 状态的所有 Thread 对象列表。 * main_thread() 方法返回主线程对象,即启动 ...

    meff:MEFF-Magento扩展文件查找器

    # or if you are in the current working directory php meff.php Extension_Name 您也可以通过modman安装它: modman clone https://github.com/tegansnyder/meff.git 例子: ➜ ...

    学单片机必备的keil2软件

    选择Update Current Installation升级安装,将可以保持原来的序列号,不必再次输入 3.选择Full安装,Next->Yes(接受版权信息)->选择安装目录->Next->输入序列号、姓名、公司 等,除了序列号以外,都随意,可以如实...

    keil C51完全破解版V2

    选择Update Current Installation升级安装,将可以保持原来的序列号,不必再次输入 3.选择Full安装,Next->Yes(接受版权信息)->选择安装目录->Next->输入序列号、姓名、公司 等,除了序列号以外,都随意,可以如实...

    keil C51完全破解版

    全新安装,以前没有安装过或者放弃以前的序列号安装,选择Update Current Installation升级安装,将可以保持原来的序列号,不必再次输入; 3.选择Full安装,Next->Yes(接受版权信息)->选择安装目录->Next->输入...

    FastReport VCL 6.6.12 Enterprise Full Source.rar

    Current version ---------------------------- + [Lazarus] Added LazChart RTTI modules - Fixed bug when reports threads may stall inside IIS DLL (New synch threads mechanism for DLL). - [Lazarus] Fixed...

    FastReport VCL 6.6.11 Enterprise Installer.rar

    Current version ---------------------------- + [Lazarus] Added LazChart RTTI modules - Fixed bug when reports threads may stall inside IIS DLL (New synch threads mechanism for DLL). - [Lazarus] Fixed...

Global site tag (gtag.js) - Google Analytics