惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

人人都是产品经理
人人都是产品经理
Stack Overflow Blog
Stack Overflow Blog
S
SegmentFault 最新的问题
博客园 - 司徒正美
aimingoo的专栏
aimingoo的专栏
U
Unit 42
GbyAI
GbyAI
B
Blog RSS Feed
博客园 - Franky
L
LangChain Blog
Hugging Face - Blog
Hugging Face - Blog
美团技术团队
The GitHub Blog
The GitHub Blog
Y
Y Combinator Blog
云风的 BLOG
云风的 BLOG
H
Hackread – Cybersecurity News, Data Breaches, AI and More
博客园 - 三生石上(FineUI控件)
Microsoft Azure Blog
Microsoft Azure Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
G
Google Developers Blog
Last Week in AI
Last Week in AI
阮一峰的网络日志
阮一峰的网络日志
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Apple Machine Learning Research
Apple Machine Learning Research

博客园 - 电工男

关于电感,电抗器的Q值(品质因数) 好久不写博了. 精辟对联 escape、encodeURI 、encodeURIComponent 编码与解码 Content-Disposition中filename字段的字符编码技巧[转] 转! 主键的使用 重载,继承,重写和多态的区别 webcast不更新了? sql server 日期类型 SQL中判断字符串中包含字符的方法 ASP.NET生成的HTML代码 win7禁用休眠,献给c盘空间不足的朋友. SQLServer2005和2008的分页技术比较[转] 浏览器兼容性系列--浅谈window.attachEvent 在ASP.NET 的服务器端控件中有三种关于 ID 的属性 jQuery对<img>赋值 MVC JQuery 为<input>赋值 jquery怎么创建一个img标签 asp.net中弹出确认窗口(confirm),实现删除确认的功能
比较 IDENT_CURRENT、@@IDENTITY 和 SCOPE_IDENTITY 返回的标...
电工男 · 2015-01-02 · via 博客园 - 电工男
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.*/

其实自己试试就明白了,完整的代码如下:

 1 USE AdventureWorks2008R2;
 2 GO
 3 IF OBJECT_ID(N't6', N'U') IS NOT NULL 
 4     DROP TABLE t6;
 5 GO
 6 IF OBJECT_ID(N't7', N'U') IS NOT NULL 
 7     DROP TABLE t7;
 8 GO
 9 CREATE TABLE t6(id int IDENTITY);
10 CREATE TABLE t7(id int IDENTITY(100,1));
11 GO
12 CREATE TRIGGER t6ins ON t6 FOR INSERT 
13 AS
14 BEGIN
15    INSERT t7 DEFAULT VALUES
16 END;
17 GO
18 --End of trigger definition
19 
20 SELECT id FROM t6;
21 --IDs empty.
22 
23 SELECT id FROM t7;
24 --ID is empty.
25 
26 --Do the following in Session 1
27 INSERT t6 DEFAULT VALUES;
28 SELECT @@IDENTITY;
29 /*Returns the value 100. This was inserted by the trigger.*/
30 
31 SELECT SCOPE_IDENTITY();
32 /* Returns the value 1. This was inserted by the 
33 INSERT statement two statements before this query.*/
34 
35 SELECT IDENT_CURRENT('t7');
36 /* Returns value inserted into t7, that is in the trigger.*/
37 
38 SELECT IDENT_CURRENT('t6');
39 /* Returns value inserted into t6. This was the INSERT statement four statements before this query.*/
40 
41 -- Do the following in Session 2.
42 SELECT @@IDENTITY;
43 /* Returns NULL because there has been no INSERT action 
44 up to this point in this session.*/
45 
46 SELECT SCOPE_IDENTITY();
47 /* Returns NULL because there has been no INSERT action 
48 up to this point in this scope in this session.*/
49 
50 SELECT IDENT_CURRENT('t7');
51 /* Returns the last value inserted into t7.*/

View Code

参考:http://msdn.microsoft.com/zh-cn/library/ms175098(SQL.105).aspx