<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: SQL SERVER &#8211; @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT &#8211; Retrieve Last Inserted Identity of Record</title>
	<atom:link href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/</link>
	<description>Personal Notes of Pinal Dave</description>
	<lastBuildDate>Wed, 22 May 2013 19:03:49 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Ashish</title>
		<link>http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-466677</link>
		<dc:creator><![CDATA[Ashish]]></dc:creator>
		<pubDate>Tue, 30 Apr 2013 11:37:35 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/03/25/identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-466677</guid>
		<description><![CDATA[Hi,
In the para for SELECT SCOPE_IDENTITY() you mention below text at the end of the para.

 In other words, it will return the last identity value that you explicitly created, rather than any identity that was created by a trigger or a user defined function.

Can User defined function create any identity ? If yes please let me know how. I think UDF can&#039;t perform any DML operation.]]></description>
		<content:encoded><![CDATA[<p>Hi,<br />
In the para for SELECT SCOPE_IDENTITY() you mention below text at the end of the para.</p>
<p> In other words, it will return the last identity value that you explicitly created, rather than any identity that was created by a trigger or a user defined function.</p>
<p>Can User defined function create any identity ? If yes please let me know how. I think UDF can&#8217;t perform any DML operation.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SQL SERVER &#8211; Weekly Series &#8211; Memory Lane &#8211; #022 &#124; SQL Server Journey with SQL Authority</title>
		<link>http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-446865</link>
		<dc:creator><![CDATA[SQL SERVER &#8211; Weekly Series &#8211; Memory Lane &#8211; #022 &#124; SQL Server Journey with SQL Authority]]></dc:creator>
		<pubDate>Sat, 30 Mar 2013 01:30:29 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/03/25/identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-446865</guid>
		<description><![CDATA[[...] @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record This was one of the most interesting blog posts I have ever written. This blog post I wrote as I have been receiving lots of questions related to identity. To avoid the potential problems associated with adding a trigger later on, always use SCOPE_IDENTITY() to return the identity of the recently added row in your T SQL Statement or Stored Procedure. [...]]]></description>
		<content:encoded><![CDATA[<p>[...] @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record This was one of the most interesting blog posts I have ever written. This blog post I wrote as I have been receiving lots of questions related to identity. To avoid the potential problems associated with adding a trigger later on, always use SCOPE_IDENTITY() to return the identity of the recently added row in your T SQL Statement or Stored Procedure. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dhwanidesai28</title>
		<link>http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-429062</link>
		<dc:creator><![CDATA[dhwanidesai28]]></dc:creator>
		<pubDate>Thu, 28 Feb 2013 08:55:11 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/03/25/identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-429062</guid>
		<description><![CDATA[I am using stored procedure and I am passing table name as parameter. SO in this case how could I use SELECT IDENT_CURRENT(‘tablename’)?]]></description>
		<content:encoded><![CDATA[<p>I am using stored procedure and I am passing table name as parameter. SO in this case how could I use SELECT IDENT_CURRENT(‘tablename’)?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dhwani</title>
		<link>http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-429061</link>
		<dc:creator><![CDATA[Dhwani]]></dc:creator>
		<pubDate>Thu, 28 Feb 2013 08:53:07 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/03/25/identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-429061</guid>
		<description><![CDATA[I am passing table name as parameter in my stored procedure and I want to get that table&#039;s last inserted row&#039;s Id. How can I do that? I want to get last row&#039;s id through SELECT IDENT_CURRENT]]></description>
		<content:encoded><![CDATA[<p>I am passing table name as parameter in my stored procedure and I want to get that table&#8217;s last inserted row&#8217;s Id. How can I do that? I want to get last row&#8217;s id through SELECT IDENT_CURRENT</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: basker</title>
		<link>http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-418414</link>
		<dc:creator><![CDATA[basker]]></dc:creator>
		<pubDate>Wed, 06 Feb 2013 04:39:30 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/03/25/identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-418414</guid>
		<description><![CDATA[Hi Pinal,
I have one question. 
i want to insert identity column into next table.
table1(col1(identity) pk, name)
table2(childname,col1 fk)

in  a sinlge transaction stored procedure i want to insert two one records in both the table . like one record in table 1 and get the seed number and insert into second table and i want to return the seed value. so that i can catch it using output paramater direction from .net

like
declare @seedvalue bigint
insert table1(name)values(&#039;basker&#039;)
set @seedvalue=@@identity
insert table(childname,col1)values(&#039;baskerchild&#039;,@seedvalue)
return @seedvalue

is this correct?

can i use DML after setting @@identity seed value to any variable ?

please reply

thanks in advance]]></description>
		<content:encoded><![CDATA[<p>Hi Pinal,<br />
I have one question.<br />
i want to insert identity column into next table.<br />
table1(col1(identity) pk, name)<br />
table2(childname,col1 fk)</p>
<p>in  a sinlge transaction stored procedure i want to insert two one records in both the table . like one record in table 1 and get the seed number and insert into second table and i want to return the seed value. so that i can catch it using output paramater direction from .net</p>
<p>like<br />
declare @seedvalue bigint<br />
insert table1(name)values(&#8216;basker&#8217;)<br />
set @seedvalue=@@identity<br />
insert table(childname,col1)values(&#8216;baskerchild&#8217;,@seedvalue)<br />
return @seedvalue</p>
<p>is this correct?</p>
<p>can i use DML after setting @@identity seed value to any variable ?</p>
<p>please reply</p>
<p>thanks in advance</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeff</title>
		<link>http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-408980</link>
		<dc:creator><![CDATA[Jeff]]></dc:creator>
		<pubDate>Thu, 17 Jan 2013 15:12:04 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/03/25/identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-408980</guid>
		<description><![CDATA[Thank you again. I&#039;ve just bought 2 of your books. As always, you were the go to guy. One addition to this for anyone who doesn&#039;t know. To set the return value to an output parameter do this:
set @NameOfYourIDParamter = (select SCOPE_IDENTITY())--return new row ID]]></description>
		<content:encoded><![CDATA[<p>Thank you again. I&#8217;ve just bought 2 of your books. As always, you were the go to guy. One addition to this for anyone who doesn&#8217;t know. To set the return value to an output parameter do this:<br />
set @NameOfYourIDParamter = (select SCOPE_IDENTITY())&#8211;return new row ID</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sd</title>
		<link>http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-397197</link>
		<dc:creator><![CDATA[sd]]></dc:creator>
		<pubDate>Fri, 21 Dec 2012 15:30:13 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/03/25/identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-397197</guid>
		<description><![CDATA[thanks for u r article. help to resolve my problem...........]]></description>
		<content:encoded><![CDATA[<p>thanks for u r article. help to resolve my problem&#8230;&#8230;&#8230;..</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Krishna</title>
		<link>http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-342510</link>
		<dc:creator><![CDATA[Krishna]]></dc:creator>
		<pubDate>Mon, 10 Sep 2012 12:34:59 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/03/25/identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-342510</guid>
		<description><![CDATA[good article, every time ur only the best. If i get doubt regarding sql then i do search question+by ur name only Iam great fan of u sir. Thank you.]]></description>
		<content:encoded><![CDATA[<p>good article, every time ur only the best. If i get doubt regarding sql then i do search question+by ur name only Iam great fan of u sir. Thank you.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: santosh kadam</title>
		<link>http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-337389</link>
		<dc:creator><![CDATA[santosh kadam]]></dc:creator>
		<pubDate>Sat, 25 Aug 2012 20:31:38 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/03/25/identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-337389</guid>
		<description><![CDATA[In continuation with above thread..
@@identity give correct value when i run some on code on SQL editor, but when i did same thing on existing Stored procedure then it give different value.
This is because @@Identity returns the last identity value inserted in any table or session of the database and so in a high (or even medium) concurrency environment @Identity will give you unexpected values

Thanks]]></description>
		<content:encoded><![CDATA[<p>In continuation with above thread..<br />
@@identity give correct value when i run some on code on SQL editor, but when i did same thing on existing Stored procedure then it give different value.<br />
This is because @@Identity returns the last identity value inserted in any table or session of the database and so in a high (or even medium) concurrency environment @Identity will give you unexpected values</p>
<p>Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: santosh kadam</title>
		<link>http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-337386</link>
		<dc:creator><![CDATA[santosh kadam]]></dc:creator>
		<pubDate>Sat, 25 Aug 2012 20:21:22 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/03/25/identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-337386</guid>
		<description><![CDATA[Hi Pinal,
Thanks a lot for wonderful site.

This is related to @@Identity, I want get latest value inserted in table.
But as per this thread @@identity does not give latest value inserted in table

While searching on other sites i got exact and i am sure correct solution, below is the link
http://weblogs.asp.net/esanchez/archive/2006/04/24/443757.aspx#7180719

Solution 1:


    CREATE TABLE HumanResources.Employees(
      Id int IDENTITY(1,1) NOT NULL,
      -- Other columns    ,
    CONSTRAINT [PK_Employees] PRIMARY KEY CLUSTERED (Id ASC)
    )
---------------------------------------------------------------------

DECLARE @InsertedRows AS TABLE (Id int)
DECLARE @NewId AS INT

INSERT INTO HumanResources.Employees
  ( /* column names */)
OUTPUT Inserted.Id INTO @InsertedRows
  VALUES (/* column values */)

SELECT @NewId = Id FROM @InsertedRows

Solution 2: 
This might helpful..
ex:

Create 
(   Id int IDENTITY(1,1) NOT NULL,
    colname varchar(20)
)

Begin Tran

INSERT into  (ColName) values (xxxxxx)

Select max(id) from 

End

Solution 2 can work for small kind of data.

Thanks]]></description>
		<content:encoded><![CDATA[<p>Hi Pinal,<br />
Thanks a lot for wonderful site.</p>
<p>This is related to @@Identity, I want get latest value inserted in table.<br />
But as per this thread @@identity does not give latest value inserted in table</p>
<p>While searching on other sites i got exact and i am sure correct solution, below is the link<br />
<a href="http://weblogs.asp.net/esanchez/archive/2006/04/24/443757.aspx#7180719" rel="nofollow">http://weblogs.asp.net/esanchez/archive/2006/04/24/443757.aspx#7180719</a></p>
<p>Solution 1:</p>
<p>    CREATE TABLE HumanResources.Employees(<br />
      Id int IDENTITY(1,1) NOT NULL,<br />
      &#8212; Other columns    ,<br />
    CONSTRAINT [PK_Employees] PRIMARY KEY CLUSTERED (Id ASC)<br />
    )<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>DECLARE @InsertedRows AS TABLE (Id int)<br />
DECLARE @NewId AS INT</p>
<p>INSERT INTO HumanResources.Employees<br />
  ( /* column names */)<br />
OUTPUT Inserted.Id INTO @InsertedRows<br />
  VALUES (/* column values */)</p>
<p>SELECT @NewId = Id FROM @InsertedRows</p>
<p>Solution 2:<br />
This might helpful..<br />
ex:</p>
<p>Create<br />
(   Id int IDENTITY(1,1) NOT NULL,<br />
    colname varchar(20)<br />
)</p>
<p>Begin Tran</p>
<p>INSERT into  (ColName) values (xxxxxx)</p>
<p>Select max(id) from </p>
<p>End</p>
<p>Solution 2 can work for small kind of data.</p>
<p>Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nalaka</title>
		<link>http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-316278</link>
		<dc:creator><![CDATA[Nalaka]]></dc:creator>
		<pubDate>Fri, 20 Jul 2012 09:21:05 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/03/25/identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-316278</guid>
		<description><![CDATA[Tanx Paul. This is what i needed.]]></description>
		<content:encoded><![CDATA[<p>Tanx Paul. This is what i needed.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jordan Gomila</title>
		<link>http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-315977</link>
		<dc:creator><![CDATA[Jordan Gomila]]></dc:creator>
		<pubDate>Thu, 19 Jul 2012 17:33:10 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/03/25/identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-315977</guid>
		<description><![CDATA[Hello, I am using a MS Access front end that uses ODBC to connect to a MS SQL Server 2005 with replicated tables.
Some times I had to remove and add again the merge database for identity problems.
there is any workarround to change the @@identity for scope_identity() in default to avoid the problems ??
I am not writing the SQL code, then I cant chose one or the other.
Inserting records in a vincled form is showing a register diferent than the inserted into de database and is producing errors.]]></description>
		<content:encoded><![CDATA[<p>Hello, I am using a MS Access front end that uses ODBC to connect to a MS SQL Server 2005 with replicated tables.<br />
Some times I had to remove and add again the merge database for identity problems.<br />
there is any workarround to change the @@identity for scope_identity() in default to avoid the problems ??<br />
I am not writing the SQL code, then I cant chose one or the other.<br />
Inserting records in a vincled form is showing a register diferent than the inserted into de database and is producing errors.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: venkat</title>
		<link>http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-307494</link>
		<dc:creator><![CDATA[venkat]]></dc:creator>
		<pubDate>Fri, 29 Jun 2012 14:36:26 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/03/25/identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-307494</guid>
		<description><![CDATA[i have a table with around 10,000 records. one of the column in the table is having identity. i have only deleted, but not truncated all the records in the table to keep my identity value. without having any records in the table, i need to find out my latest identity value. Can you let me know how to find the latest identity value without having any records in the table. Please update your comments on this?]]></description>
		<content:encoded><![CDATA[<p>i have a table with around 10,000 records. one of the column in the table is having identity. i have only deleted, but not truncated all the records in the table to keep my identity value. without having any records in the table, i need to find out my latest identity value. Can you let me know how to find the latest identity value without having any records in the table. Please update your comments on this?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul</title>
		<link>http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-298051</link>
		<dc:creator><![CDATA[Paul]]></dc:creator>
		<pubDate>Sat, 09 Jun 2012 11:42:26 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/03/25/identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-298051</guid>
		<description><![CDATA[There is an important difference between IDENT_CURRENT versus SCOPE_IDENTITYand @@IDENTITY when referencing the IDENTITY value within an INSERT statement. See below for an example


CREATE TABLE [dbo].[t_TestIdentity](
	[TestID] [bigint] IDENTITY(1,1) NOT NULL,
	[TestIDCopy] [bigint] NULL,
	[TestText] [nvarchar](32) NULL,
 CONSTRAINT [PK_TestID] PRIMARY KEY CLUSTERED 
([TestID] ASC)
)

GO

INSERT [dbo].[t_TestIdentity] ([TestIDCopy], [TestText]) VALUES (IDENT_CURRENT(&#039;[dbo].[t_TestIdentity]&#039;), &#039;Test1&#039;)
INSERT [dbo].[t_TestIdentity] ([TestIDCopy], [TestText]) VALUES (SCOPE_IDENTITY(), &#039;Test2&#039;)
INSERT [dbo].[t_TestIdentity] ([TestIDCopy], [TestText]) VALUES (@@IDENTITY, &#039;Test3&#039;)

SELECT * FROM [dbo].[t_TestIdentity]

TestID	TestIDCopy	TestText
1	1	Test1
2	1	Test2
3	2	Test3]]></description>
		<content:encoded><![CDATA[<p>There is an important difference between IDENT_CURRENT versus SCOPE_IDENTITYand @@IDENTITY when referencing the IDENTITY value within an INSERT statement. See below for an example</p>
<p>CREATE TABLE [dbo].[t_TestIdentity](<br />
	[TestID] [bigint] IDENTITY(1,1) NOT NULL,<br />
	[TestIDCopy] [bigint] NULL,<br />
	[TestText] [nvarchar](32) NULL,<br />
 CONSTRAINT [PK_TestID] PRIMARY KEY CLUSTERED<br />
([TestID] ASC)<br />
)</p>
<p>GO</p>
<p>INSERT [dbo].[t_TestIdentity] ([TestIDCopy], [TestText]) VALUES (IDENT_CURRENT(&#8216;[dbo].[t_TestIdentity]&#8216;), &#8216;Test1&#8242;)<br />
INSERT [dbo].[t_TestIdentity] ([TestIDCopy], [TestText]) VALUES (SCOPE_IDENTITY(), &#8216;Test2&#8242;)<br />
INSERT [dbo].[t_TestIdentity] ([TestIDCopy], [TestText]) VALUES (@@IDENTITY, &#8216;Test3&#8242;)</p>
<p>SELECT * FROM [dbo].[t_TestIdentity]</p>
<p>TestID	TestIDCopy	TestText<br />
1	1	Test1<br />
2	1	Test2<br />
3	2	Test3</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nalaka</title>
		<link>http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-288487</link>
		<dc:creator><![CDATA[Nalaka]]></dc:creator>
		<pubDate>Fri, 25 May 2012 10:51:44 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/03/25/identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-288487</guid>
		<description><![CDATA[MyPK is the identity value of the MyTable2. it does not contain in the MyTable1. here i need current inserting row identity. just removing braces gives Invalid column name &#039;MyPK&#039;]]></description>
		<content:encoded><![CDATA[<p>MyPK is the identity value of the MyTable2. it does not contain in the MyTable1. here i need current inserting row identity. just removing braces gives Invalid column name &#8216;MyPK&#8217;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: madhivanan</title>
		<link>http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-287932</link>
		<dc:creator><![CDATA[madhivanan]]></dc:creator>
		<pubDate>Thu, 24 May 2012 10:08:39 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/03/25/identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-287932</guid>
		<description><![CDATA[Remove the braces

INSERT INTO MyTable2
 (MyColumn1,MyColumn2)
 select ‘A’ , ‘B’+MyPk from MyTable1]]></description>
		<content:encoded><![CDATA[<p>Remove the braces</p>
<p>INSERT INTO MyTable2<br />
 (MyColumn1,MyColumn2)<br />
 select ‘A’ , ‘B’+MyPk from MyTable1</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nalaka</title>
		<link>http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-287844</link>
		<dc:creator><![CDATA[Nalaka]]></dc:creator>
		<pubDate>Thu, 24 May 2012 05:30:36 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/03/25/identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-287844</guid>
		<description><![CDATA[Hi Pinal,

CREATE TABLE MyTable2
(
        MyPK int identity,
        MyColumn1 NVARCHAR(100),
        MyColumn2 NVARCHAR(100)
)

INSERT INTO MyTable2
(MyColumn1,MyColumn2)
(select &#039;A&#039; , &#039;B&#039;  from MyTable1)

Here I&#039;m using select statement to insert records to MyTable2. MyTable1 contains say, 100 records.

now i need to use above to insert a GUID to MyTable2.MyColumn2 by combining MyPk (Current Value). 

something like bellow 

INSERT INTO MyTable2
(MyColumn1,MyColumn2)
(select  &#039;A&#039; , &#039;B&#039;+MyPk  from MyTable1)

How can I do this? Inserting records should be from a select statement.]]></description>
		<content:encoded><![CDATA[<p>Hi Pinal,</p>
<p>CREATE TABLE MyTable2<br />
(<br />
        MyPK int identity,<br />
        MyColumn1 NVARCHAR(100),<br />
        MyColumn2 NVARCHAR(100)<br />
)</p>
<p>INSERT INTO MyTable2<br />
(MyColumn1,MyColumn2)<br />
(select &#8216;A&#8217; , &#8216;B&#8217;  from MyTable1)</p>
<p>Here I&#8217;m using select statement to insert records to MyTable2. MyTable1 contains say, 100 records.</p>
<p>now i need to use above to insert a GUID to MyTable2.MyColumn2 by combining MyPk (Current Value). </p>
<p>something like bellow </p>
<p>INSERT INTO MyTable2<br />
(MyColumn1,MyColumn2)<br />
(select  &#8216;A&#8217; , &#8216;B&#8217;+MyPk  from MyTable1)</p>
<p>How can I do this? Inserting records should be from a select statement.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: madhivanan</title>
		<link>http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-287558</link>
		<dc:creator><![CDATA[madhivanan]]></dc:creator>
		<pubDate>Wed, 23 May 2012 11:01:18 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/03/25/identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-287558</guid>
		<description><![CDATA[Do explicate update after bulk insert]]></description>
		<content:encoded><![CDATA[<p>Do explicate update after bulk insert</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: madhivanan</title>
		<link>http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-287527</link>
		<dc:creator><![CDATA[madhivanan]]></dc:creator>
		<pubDate>Wed, 23 May 2012 10:21:16 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/03/25/identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-287527</guid>
		<description><![CDATA[Not. It depends on the sessions they have used]]></description>
		<content:encoded><![CDATA[<p>Not. It depends on the sessions they have used</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: hntripathi</title>
		<link>http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-285660</link>
		<dc:creator><![CDATA[hntripathi]]></dc:creator>
		<pubDate>Fri, 18 May 2012 06:12:35 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/03/25/identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-285660</guid>
		<description><![CDATA[Dear Pinal,

Can Scope_Identity(), ident_current() and @@identity gives always 100% correct result?]]></description>
		<content:encoded><![CDATA[<p>Dear Pinal,</p>
<p>Can Scope_Identity(), ident_current() and @@identity gives always 100% correct result?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pranav</title>
		<link>http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-284746</link>
		<dc:creator><![CDATA[Pranav]]></dc:creator>
		<pubDate>Tue, 15 May 2012 10:08:15 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/03/25/identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-284746</guid>
		<description><![CDATA[Hi Pinal,
                I have 1 doubt.Pls clarify me. I created 1 table.In that i am inserting 5 records at a time using bulk insert in xml.I want the record status as 1 should display for those 5 records repeatedly and for next insertion it should display as 2 for next 5 records. Is it possible. pls help me with an example.]]></description>
		<content:encoded><![CDATA[<p>Hi Pinal,<br />
                I have 1 doubt.Pls clarify me. I created 1 table.In that i am inserting 5 records at a time using bulk insert in xml.I want the record status as 1 should display for those 5 records repeatedly and for next insertion it should display as 2 for next 5 records. Is it possible. pls help me with an example.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: wewerwre</title>
		<link>http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-283512</link>
		<dc:creator><![CDATA[wewerwre]]></dc:creator>
		<pubDate>Thu, 10 May 2012 06:54:17 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/03/25/identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-283512</guid>
		<description><![CDATA[its insert in same table]]></description>
		<content:encoded><![CDATA[<p>its insert in same table</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Preeti Rathore</title>
		<link>http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-268012</link>
		<dc:creator><![CDATA[Preeti Rathore]]></dc:creator>
		<pubDate>Mon, 26 Mar 2012 18:34:14 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/03/25/identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-268012</guid>
		<description><![CDATA[Hi pinal,

How to change identity column values (Update) ?

I have a MS SQL 2005 database with a table Test with column ID. ID is a identity column. I have rows in this table and all of them have their corresponding ID autoincremented value.

ID	Name
1	abc
2	def
3	ghi
4	jkl


Now I would like to change every ID in this table like this:
ID	      Name
5001	abc
5002	def
3	        ghi
4	        jkl

But when I do this I get error:

Cannot update identity column &#039;ID&#039;.
I&#039;ve tried with:

ALTER TABLE Test NOCHECK CONSTRAINT ALL 
set identity_insert ID OFF/ON
But this does not solve this problem.]]></description>
		<content:encoded><![CDATA[<p>Hi pinal,</p>
<p>How to change identity column values (Update) ?</p>
<p>I have a MS SQL 2005 database with a table Test with column ID. ID is a identity column. I have rows in this table and all of them have their corresponding ID autoincremented value.</p>
<p>ID	Name<br />
1	abc<br />
2	def<br />
3	ghi<br />
4	jkl</p>
<p>Now I would like to change every ID in this table like this:<br />
ID	      Name<br />
5001	abc<br />
5002	def<br />
3	        ghi<br />
4	        jkl</p>
<p>But when I do this I get error:</p>
<p>Cannot update identity column &#8216;ID&#8217;.<br />
I&#8217;ve tried with:</p>
<p>ALTER TABLE Test NOCHECK CONSTRAINT ALL<br />
set identity_insert ID OFF/ON<br />
But this does not solve this problem.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ken</title>
		<link>http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-266228</link>
		<dc:creator><![CDATA[Ken]]></dc:creator>
		<pubDate>Thu, 22 Mar 2012 19:27:13 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/03/25/identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-266228</guid>
		<description><![CDATA[Note that in help, it documents that rollback will remove the record, but not the identity change produced by the attempted insert. I&#039;ve also verified all three identity methods return the same answer after a rollback. (Since my tests didn&#039;t involve a trigger.)

Note also that IDENT_CURRENT will only work on the last record inserted on THIS server if the table is merge replicated. Hmmm, I&#039;ve never tried &#039;srvr.dbNm.dbo.tbl&#039; before. I could be wrong about that.]]></description>
		<content:encoded><![CDATA[<p>Note that in help, it documents that rollback will remove the record, but not the identity change produced by the attempted insert. I&#8217;ve also verified all three identity methods return the same answer after a rollback. (Since my tests didn&#8217;t involve a trigger.)</p>
<p>Note also that IDENT_CURRENT will only work on the last record inserted on THIS server if the table is merge replicated. Hmmm, I&#8217;ve never tried &#8216;srvr.dbNm.dbo.tbl&#8217; before. I could be wrong about that.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ken</title>
		<link>http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-266219</link>
		<dc:creator><![CDATA[Ken]]></dc:creator>
		<pubDate>Thu, 22 Mar 2012 19:02:55 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/03/25/identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/#comment-266219</guid>
		<description><![CDATA[Actually, if you have a stored procedure or function defined in the remote server and it executes scope_identity, it WILL work properly. It will then be up to the function or sproc to return the value to you on your server.

Also, it depends on what you mean by a different server. If you connect to SQL on one server, execute a command that crosses to a different SQL server, that IS a different server.

If you connect to SQL on a different server than the one you are on, that is NOT a different server.

You shouldn&#039;t be doing things directly to a table on a different server anyway. That is a bad security model. Also, that can affect your permission to execute other things that aren&#039;t allowed across servers that become available when you touch them by sproc or func. (Like locking hints.)]]></description>
		<content:encoded><![CDATA[<p>Actually, if you have a stored procedure or function defined in the remote server and it executes scope_identity, it WILL work properly. It will then be up to the function or sproc to return the value to you on your server.</p>
<p>Also, it depends on what you mean by a different server. If you connect to SQL on one server, execute a command that crosses to a different SQL server, that IS a different server.</p>
<p>If you connect to SQL on a different server than the one you are on, that is NOT a different server.</p>
<p>You shouldn&#8217;t be doing things directly to a table on a different server anyway. That is a bad security model. Also, that can affect your permission to execute other things that aren&#8217;t allowed across servers that become available when you touch them by sproc or func. (Like locking hints.)</p>
]]></content:encoded>
	</item>
</channel>
</rss>
