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

推荐订阅源

Attack and Defense Labs
Attack and Defense Labs
The GitHub Blog
The GitHub Blog
C
Check Point Blog
博客园_首页
MongoDB | Blog
MongoDB | Blog
N
Netflix TechBlog - Medium
F
Full Disclosure
Microsoft Security Blog
Microsoft Security Blog
爱范儿
爱范儿
Recent Announcements
Recent Announcements
阮一峰的网络日志
阮一峰的网络日志
G
GRAHAM CLULEY
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
T
Threat Research - Cisco Blogs
C
Cybersecurity and Infrastructure Security Agency CISA
V
Vulnerabilities – Threatpost
K
Kaspersky official blog
博客园 - 司徒正美
S
Schneier on Security
T
The Exploit Database - CXSecurity.com
Project Zero
Project Zero
云风的 BLOG
云风的 BLOG
Cisco Talos Blog
Cisco Talos Blog
Know Your Adversary
Know Your Adversary
雷峰网
雷峰网
V
V2EX - 技术
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Spread Privacy
Spread Privacy
罗磊的独立博客
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
S
Security Affairs
SecWiki News
SecWiki News
Schneier on Security
Schneier on Security
O
OpenAI News
Jina AI
Jina AI
PCI Perspectives
PCI Perspectives
Cyberwarzone
Cyberwarzone
Y
Y Combinator Blog
Apple Machine Learning Research
Apple Machine Learning Research
B
Blog RSS Feed
I
InfoQ
D
Docker
P
Palo Alto Networks Blog
Recorded Future
Recorded Future
M
MIT News - Artificial intelligence
博客园 - Franky
B
Blog
Scott Helme
Scott Helme
博客园 - 叶小钗
D
DataBreaches.Net

博客园 - 电工男

关于电感,电抗器的Q值(品质因数) 好久不写博了. 精辟对联 escape、encodeURI 、encodeURIComponent 编码与解码 Content-Disposition中filename字段的字符编码技巧[转] 转! 主键的使用 重载,继承,重写和多态的区别 webcast不更新了? sql server 日期类型 SQL中判断字符串中包含字符的方法 ASP.NET生成的HTML代码 win7禁用休眠,献给c盘空间不足的朋友. SQLServer2005和2008的分页技术比较[转] 浏览器兼容性系列--浅谈window.attachEvent 在ASP.NET 的服务器端控件中有三种关于 ID 的属性 jQuery对&lt;img&gt;赋值 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