<?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/"
	>
<channel>
	<title>Comments on: SQL SERVER - @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT - 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>Notes of a SQL Server MVP and Database Administrator</description>
	<pubDate>Tue, 06 Jan 2009 15:42:08 +0000</pubDate>
	<generator>http://wordpress.org/?v=MU</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Jai</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-44782</link>
		<dc:creator>Jai</dc:creator>
		<pubDate>Sun, 14 Dec 2008 05:15: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-44782</guid>
		<description>Excellent, it's very clear and understandable article.


Thanks</description>
		<content:encoded><![CDATA[<p>Excellent, it&#8217;s very clear and understandable article.</p>
<p>Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Seema</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-44457</link>
		<dc:creator>Seema</dc:creator>
		<pubDate>Mon, 01 Dec 2008 06:35:32 +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-44457</guid>
		<description>Good Article</description>
		<content:encoded><![CDATA[<p>Good Article</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: nofar</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-44261</link>
		<dc:creator>nofar</dc:creator>
		<pubDate>Tue, 18 Nov 2008 04:20: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-44261</guid>
		<description>hello sir,
please send me the query of fetch 10 random rows from table,</description>
		<content:encoded><![CDATA[<p>hello sir,<br />
please send me the query of fetch 10 random rows from table,</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bharathidasan</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-44132</link>
		<dc:creator>Bharathidasan</dc:creator>
		<pubDate>Mon, 10 Nov 2008 06:54:24 +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-44132</guid>
		<description>Hello sir,

i have 1 doubt. how can i retrieve last 10 records from a particular table.

pls i want answer for this</description>
		<content:encoded><![CDATA[<p>Hello sir,</p>
<p>i have 1 doubt. how can i retrieve last 10 records from a particular table.</p>
<p>pls i want answer for this</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joggee</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-43968</link>
		<dc:creator>Joggee</dc:creator>
		<pubDate>Thu, 30 Oct 2008 07:48: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-43968</guid>
		<description>My problem resolve. God Bless you. 
I always have a first choice to search here.

Keep up the good work.

Joggee</description>
		<content:encoded><![CDATA[<p>My problem resolve. God Bless you.<br />
I always have a first choice to search here.</p>
<p>Keep up the good work.</p>
<p>Joggee</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rohit Hans</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-43872</link>
		<dc:creator>Rohit Hans</dc:creator>
		<pubDate>Thu, 23 Oct 2008 07:36:46 +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-43872</guid>
		<description>Thanks very much. It really helped me to understand difference between various options of identity.</description>
		<content:encoded><![CDATA[<p>Thanks very much. It really helped me to understand difference between various options of identity.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ayyappan</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-43740</link>
		<dc:creator>Ayyappan</dc:creator>
		<pubDate>Thu, 16 Oct 2008 09:45:37 +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-43740</guid>
		<description>Can we have more than one identity column in a table?

if yes, please tell me how we can do that?

Thanks</description>
		<content:encoded><![CDATA[<p>Can we have more than one identity column in a table?</p>
<p>if yes, please tell me how we can do that?</p>
<p>Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sham</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-43505</link>
		<dc:creator>sham</dc:creator>
		<pubDate>Sat, 04 Oct 2008 09:26:19 +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-43505</guid>
		<description>nice one .. thnk you</description>
		<content:encoded><![CDATA[<p>nice one .. thnk you</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: santhosh</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-42880</link>
		<dc:creator>santhosh</dc:creator>
		<pubDate>Wed, 17 Sep 2008 09:33:08 +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-42880</guid>
		<description>i have user id table i want retrive last user id from that table 
i need sql query for pls help me</description>
		<content:encoded><![CDATA[<p>i have user id table i want retrive last user id from that table<br />
i need sql query for pls help me</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: suresh</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-42640</link>
		<dc:creator>suresh</dc:creator>
		<pubDate>Wed, 10 Sep 2008 09:56: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-42640</guid>
		<description>how can i add identity coloumn to existing coloum through query</description>
		<content:encoded><![CDATA[<p>how can i add identity coloumn to existing coloum through query</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hard2Get</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-41489</link>
		<dc:creator>Hard2Get</dc:creator>
		<pubDate>Fri, 08 Aug 2008 14:15: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-41489</guid>
		<description>The main problem is, I can't get the query result from 2 different connection with different table.
But with the same connection/server, I can get the query result.

SELECT SERVER1enroll.ID
FROM SERVER1enroll
WHERE SERVER1enroll.ID NOT IN (SELECT SERVER2enroll.ID FROM SERVER2enroll)

And is there a shortcut for that SQLcode to make a faster query than that.

Can anyone solve that?
I'm using 2 different connection, Server1 on my PC, Server2 is on the other PC.

I'm using VB9
Can anyone share some code for development testing?</description>
		<content:encoded><![CDATA[<p>The main problem is, I can&#8217;t get the query result from 2 different connection with different table.<br />
But with the same connection/server, I can get the query result.</p>
<p>SELECT SERVER1enroll.ID<br />
FROM SERVER1enroll<br />
WHERE SERVER1enroll.ID NOT IN (SELECT SERVER2enroll.ID FROM SERVER2enroll)</p>
<p>And is there a shortcut for that SQLcode to make a faster query than that.</p>
<p>Can anyone solve that?<br />
I&#8217;m using 2 different connection, Server1 on my PC, Server2 is on the other PC.</p>
<p>I&#8217;m using VB9<br />
Can anyone share some code for development testing?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: scarlett</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-39165</link>
		<dc:creator>scarlett</dc:creator>
		<pubDate>Wed, 11 Jun 2008 22:11:46 +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-39165</guid>
		<description>hi 

Please help me out.

In my stored proc, I use @ident_current of a table(Table X) as a default value for my table variables (Temp Table)

Now Since Im creating a Table Variable, I want one of its columns to have a default value of the identity of the Table X , Now when creating this Table Variable, it will not accept
a variable as a default hence forcing me to use Ident_Current(Table X) as the default. I know that this can produce erroneous data as it applies to any session .. is there another way out? I cant use @@Identity as there are 2 more Table Variables created after the insertion of Table X - Hence will pick up wrong identity value .... 
here's my code
--------------------------------------------

INSERT INTO TABLE X

DECLARE A TABLE A
INSERT INTO TABLE A

DECLARE  TABLE B
INSERT INTO TABLE B

DECLARE C TABLE (COL1, COL2 INT DEFAULT IDENT_CURRENT( 'TABLE X' ),COL3)

------------------------------------------------------------</description>
		<content:encoded><![CDATA[<p>hi </p>
<p>Please help me out.</p>
<p>In my stored proc, I use @ident_current of a table(Table X) as a default value for my table variables (Temp Table)</p>
<p>Now Since Im creating a Table Variable, I want one of its columns to have a default value of the identity of the Table X , Now when creating this Table Variable, it will not accept<br />
a variable as a default hence forcing me to use Ident_Current(Table X) as the default. I know that this can produce erroneous data as it applies to any session .. is there another way out? I cant use @@Identity as there are 2 more Table Variables created after the insertion of Table X - Hence will pick up wrong identity value &#8230;.<br />
here&#8217;s my code<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>INSERT INTO TABLE X</p>
<p>DECLARE A TABLE A<br />
INSERT INTO TABLE A</p>
<p>DECLARE  TABLE B<br />
INSERT INTO TABLE B</p>
<p>DECLARE C TABLE (COL1, COL2 INT DEFAULT IDENT_CURRENT( &#8216;TABLE X&#8217; ),COL3)</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mahee</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-38878</link>
		<dc:creator>Mahee</dc:creator>
		<pubDate>Thu, 29 May 2008 20:52:00 +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-38878</guid>
		<description>Iam having a real strange issue with both the @@identity and the scope_identity(). The problem is running the same insert on two different machines with the exact DBs and the result on machine is as expected and on the other i get null values for both. unlike the examples quoted by the users here, iam using a select statement instead of values list to insert.
And Iam using SQL 2005 w/ SP2 on both the machines. (The backward compatibility levels for  both are SQL server 2000 (80) if you need to know)

Here is what Iam doing:

INSERT INTO TEMPTABLE ( column1, column2)
SELECT t1, t2 FROMNewTable where t3 = 'somevalue';
SELECT @@IDENTITY;

INSERT INTO TEMPTABLE ( column1, column2)
SELECT t1, t2 FROMNewTable where t3 = 'somevalue';
SELECT Scope_Identity();

INSERT INTO TEMPTABLE ( column1, column2)
SELECT t1, t2 FROMNewTable where t3 = 'somevalue';
SELECT Ident_Currenty('TEMPTABLE');

One machine gives me same value on all three statements, while the other gives me null on first two and gives me a value on the third. 

Any insights will be appreciated.

- Mahee</description>
		<content:encoded><![CDATA[<p>Iam having a real strange issue with both the @@identity and the scope_identity(). The problem is running the same insert on two different machines with the exact DBs and the result on machine is as expected and on the other i get null values for both. unlike the examples quoted by the users here, iam using a select statement instead of values list to insert.<br />
And Iam using SQL 2005 w/ SP2 on both the machines. (The backward compatibility levels for  both are SQL server 2000 (80) if you need to know)</p>
<p>Here is what Iam doing:</p>
<p>INSERT INTO TEMPTABLE ( column1, column2)<br />
SELECT t1, t2 FROMNewTable where t3 = &#8217;somevalue&#8217;;<br />
SELECT @@IDENTITY;</p>
<p>INSERT INTO TEMPTABLE ( column1, column2)<br />
SELECT t1, t2 FROMNewTable where t3 = &#8217;somevalue&#8217;;<br />
SELECT Scope_Identity();</p>
<p>INSERT INTO TEMPTABLE ( column1, column2)<br />
SELECT t1, t2 FROMNewTable where t3 = &#8217;somevalue&#8217;;<br />
SELECT Ident_Currenty(&#8217;TEMPTABLE&#8217;);</p>
<p>One machine gives me same value on all three statements, while the other gives me null on first two and gives me a value on the third. </p>
<p>Any insights will be appreciated.</p>
<p>- Mahee</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jaiveer</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-38286</link>
		<dc:creator>Jaiveer</dc:creator>
		<pubDate>Sat, 17 May 2008 08:09: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-38286</guid>
		<description>Hi, Pinal,
The Solution you have given seems very problem solving. I will try this for sure. My problem is this that: I have an web application, problem is that; when more than one user enterd data on the same time the data entered wrongly i.e. user 1 data save in user2 and user 2 data saves in itself(user2)</description>
		<content:encoded><![CDATA[<p>Hi, Pinal,<br />
The Solution you have given seems very problem solving. I will try this for sure. My problem is this that: I have an web application, problem is that; when more than one user enterd data on the same time the data entered wrongly i.e. user 1 data save in user2 and user 2 data saves in itself(user2)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vijay Anand Kannan</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-38126</link>
		<dc:creator>Vijay Anand Kannan</dc:creator>
		<pubDate>Thu, 15 May 2008 15:25:46 +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-38126</guid>
		<description>Hi Viswanath,

I dont think that you can add the Identity to the existing coloumn. You need to drop the table and recreate with Identity. You can add a new column with Identity in alter table.

- Vijay Anand Kannan</description>
		<content:encoded><![CDATA[<p>Hi Viswanath,</p>
<p>I dont think that you can add the Identity to the existing coloumn. You need to drop the table and recreate with Identity. You can add a new column with Identity in alter table.</p>
<p>- Vijay Anand Kannan</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: khushboo</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-38024</link>
		<dc:creator>khushboo</dc:creator>
		<pubDate>Wed, 14 May 2008 12:39:02 +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-38024</guid>
		<description>very informative article........thanks a lot.....

but it will be more easy to understand if examples had been put here.........</description>
		<content:encoded><![CDATA[<p>very informative article&#8230;&#8230;..thanks a lot&#8230;..</p>
<p>but it will be more easy to understand if examples had been put here&#8230;&#8230;&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: srinivas</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-37275</link>
		<dc:creator>srinivas</dc:creator>
		<pubDate>Thu, 08 May 2008 07:12:53 +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-37275</guid>
		<description>to retreive the last entered record in table</description>
		<content:encoded><![CDATA[<p>to retreive the last entered record in table</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: shreya</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-35919</link>
		<dc:creator>shreya</dc:creator>
		<pubDate>Tue, 29 Apr 2008 09:14:09 +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-35919</guid>
		<description>I want to select the records from a table which are updated or added in the last one month (table doesn't have any datetime field and I can't change the structure). Is it possible to write a sql query for that?</description>
		<content:encoded><![CDATA[<p>I want to select the records from a table which are updated or added in the last one month (table doesn&#8217;t have any datetime field and I can&#8217;t change the structure). Is it possible to write a sql query for that?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Wes</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-35513</link>
		<dc:creator>Wes</dc:creator>
		<pubDate>Thu, 24 Apr 2008 20:01: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-35513</guid>
		<description>I have been running replicated servers using merge replication and SQL 2000 for about a year without issue.  I have several sp's that used @@Identity


I upgraded to SQL 2005 last week.

Guess what - those SP's are now intermittently returning the identity of a table from an associated repl trigger.

Have you seen or heard of this occurring after an upgrade?

Thank goodness I stumbled onto your article and was able to fix all instances of @@Identity in my SP's.    (Now I have to replicate the sp's manually off-hours....)


thanks
Wes</description>
		<content:encoded><![CDATA[<p>I have been running replicated servers using merge replication and SQL 2000 for about a year without issue.  I have several sp&#8217;s that used @@Identity</p>
<p>I upgraded to SQL 2005 last week.</p>
<p>Guess what - those SP&#8217;s are now intermittently returning the identity of a table from an associated repl trigger.</p>
<p>Have you seen or heard of this occurring after an upgrade?</p>
<p>Thank goodness I stumbled onto your article and was able to fix all instances of @@Identity in my SP&#8217;s.    (Now I have to replicate the sp&#8217;s manually off-hours&#8230;.)</p>
<p>thanks<br />
Wes</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vishwanath</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-35038</link>
		<dc:creator>Vishwanath</dc:creator>
		<pubDate>Mon, 14 Apr 2008 03:52:00 +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-35038</guid>
		<description>Thanks in advance for any reply.</description>
		<content:encoded><![CDATA[<p>Thanks in advance for any reply.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
