Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

My Experiments with SQLServer
Browse by Tags · View All
SQLServer 126
SQLServer 2008 R2 91
SQLServer 2008 86
SQLServer 2005 82
SQL 60
Database 59
Sql And Me 57
Tips & Tricks 28
SQL Server 27
SQL FAQ 26

Archive · View All
May 2011 25
June 2011 21
July 2011 21
August 2011 19
April 2011 16
January 2013 4
May 2012 3
April 2012 3
October 2011 3
February 2013 2

Vishal Gajjar's Blog

Using Built-in system functions – @@IDENTITY, SCOPE_IDENTITY()

Jun 1 2011 5:56AM by Vishal Gajjar   

@@IDENTITY is a system function that can be used to retrieve last inserted identity value. @@IDENTITY is not limited to scope.

for example, I have a Table which contains an identity column as below:

-- © 2011 – Vishal (http://SqlAndMe.com)
 
USE [SqlAndMe]
 
CREATE TABLE [dbo].[Temp](
      [IDNum]     INT IDENTITY(100,1) NOT NULL,
      [Name]      NCHAR(10) NULL
)

After I insert new row to table, I can use this functions to retrieve the inserted identity value.

-- © 2011 – Vishal (http://SqlAndMe.com)
 
INSERT INTO dbo.Temp VALUES ('Ahmedabad')
INSERT INTO dbo.Temp VALUES ('Bangalore')
INSERT INTO dbo.Temp VALUES ('Reading')
 
SELECT @@IDENTITY AS 'Last Inserted'

Result Set:

(1 row(s) affected)
 
(1 row(s) affected)
 
(1 row(s) affected)
Last Inserted
—————————————
186
 
(1 row(s) affected)

@@IDENTITY only returns the last identity values inserted in case of multiple inserts.

SCOPE_IDENTITY() as the name suggests is limited to the same scope in which last identity value was inserted to a column. SCOPE_IDENTITY() should be used if you need to retrieve the last inserted value from the table you inserted the rows explicitly.

Another useful function for this task is IDENT_CURRENT().

Hope This Helps! Cheers!


Republished from Sql&Me [31 clicks].  Read the original version here [32134 clicks].

Vishal Gajjar
46 · 4% · 1276
0
Liked
 
0
Lifesaver
 
0
Refreshed
 
0
Learned
 
0
Incorrect



Submit

Your Comment


Sign Up or Login to post a comment.

    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]