<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://weblogs.asp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>How to get an Identity value with SQL Server 2005</title><link>http://weblogs.asp.net/esanchez/archive/2006/04/24/443757.aspx</link><description>It's usual (actually, I'd say recommended) to have an Identity int column as primary key. I.e., it's a common thing to define a table like this : CREATE TABLE HumanResources.Employees ( Id int IDENTITY ( 1 , 1 ) NOT NULL, -- Other columns , CONSTRAINT</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>re: How to get an Identity value with SQL Server 2005</title><link>http://weblogs.asp.net/esanchez/archive/2006/04/24/443757.aspx#7180719</link><pubDate>Tue, 25 Aug 2009 04:48:02 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7180719</guid><dc:creator>sourabh</dc:creator><author>sourabh</author><description>&lt;p&gt;select max(identity column) from tablename&lt;/p&gt;
&lt;p&gt;example:&lt;/p&gt;
&lt;p&gt;create table employees&lt;/p&gt;
&lt;p&gt;(id int identity(1,1))&lt;/p&gt;
&lt;p&gt;select max(id) from employees&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7180719" width="1" height="1"&gt;</description></item><item><title>re: How to get an Identity value with SQL Server 2005</title><link>http://weblogs.asp.net/esanchez/archive/2006/04/24/443757.aspx#6896520</link><pubDate>Tue, 10 Feb 2009 08:35:19 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6896520</guid><dc:creator>Dreamer</dc:creator><author>Dreamer</author><description>&lt;p&gt;Other way simply take result from system table&lt;/p&gt;
&lt;p&gt;SELECT last_value FROM sys.identity_columns &lt;/p&gt;
&lt;p&gt;WHERE [object_id] = object_id('table_name')&lt;/p&gt;
&lt;p&gt;I read in some books that, system talbes can be diferent in different versions of SQL servers, so be aware. Anyway I use it and didn't get any problems yet. Maybe it's better to find some stored procedure like sp_*, but I didn't.&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://msdn.microsoft.com/en-us/library/ms187334.aspx"&gt;msdn.microsoft.com/.../ms187334.aspx&lt;/a&gt;&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6896520" width="1" height="1"&gt;</description></item><item><title>re: How to get an Identity value with SQL Server 2005</title><link>http://weblogs.asp.net/esanchez/archive/2006/04/24/443757.aspx#6715224</link><pubDate>Sat, 01 Nov 2008 11:58:37 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6715224</guid><dc:creator>Dreamer</dc:creator><author>Dreamer</author><description>&lt;p&gt;To get last value of identity in MsSQL:&lt;/p&gt;
&lt;p&gt;use DataBaseName&lt;/p&gt;
&lt;p&gt;Select Count(*) from TableName&lt;/p&gt;
&lt;p&gt;select IDENT_CURRENT('TableName') as LastIdentity&lt;/p&gt;
&lt;p&gt;comment:&lt;/p&gt;
&lt;p&gt;we need IDENT_CURRENT function, but it gives value of last tabe with which we were dealing lately. So then we choise database, doing anything with table which we need, and then using IDENT_CURRENT. &lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://msdn.microsoft.com/en-us/library/aa933217"&gt;msdn.microsoft.com/.../aa933217&lt;/a&gt;(SQL.80).aspx&lt;/p&gt;
&lt;p&gt;key words: How to get last increment/identity of column or table?&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6715224" width="1" height="1"&gt;</description></item><item><title>re: How to get an Identity value with SQL Server 2005</title><link>http://weblogs.asp.net/esanchez/archive/2006/04/24/443757.aspx#6668190</link><pubDate>Fri, 10 Oct 2008 06:14:49 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6668190</guid><dc:creator>Shantha</dc:creator><author>Shantha</author><description>&lt;p&gt;First Sample is good one! &lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6668190" width="1" height="1"&gt;</description></item><item><title>re: How to get an Identity value with SQL Server 2005</title><link>http://weblogs.asp.net/esanchez/archive/2006/04/24/443757.aspx#6665783</link><pubDate>Wed, 08 Oct 2008 16:16:50 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6665783</guid><dc:creator>sabuv</dc:creator><author>sabuv</author><description>&lt;p&gt;i want to get the current identity value of a table before insert the next row.&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6665783" width="1" height="1"&gt;</description></item><item><title>re: How to get an Identity value with SQL Server 2005</title><link>http://weblogs.asp.net/esanchez/archive/2006/04/24/443757.aspx#6229931</link><pubDate>Thu, 29 May 2008 18:23:25 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6229931</guid><dc:creator>Kila</dc:creator><author>Kila</author><description>&lt;p&gt;I just have to add that SCOPE_IDENTITY does NOT work with the uniqueidentifier data type, so OUTPUT is useful in that situation. SCOPE_IDENTITY only works for numeric columns&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6229931" width="1" height="1"&gt;</description></item><item><title>re: How to get an Identity value with SQL Server 2005</title><link>http://weblogs.asp.net/esanchez/archive/2006/04/24/443757.aspx#5546780</link><pubDate>Fri, 04 Jan 2008 14:10:12 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:5546780</guid><dc:creator>rohit</dc:creator><author>rohit</author><description>&lt;p&gt;@@Identity returns the last identity value inserted in *any table &lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5546780" width="1" height="1"&gt;</description></item><item><title>re: How to get an Identity value with SQL Server 2005</title><link>http://weblogs.asp.net/esanchez/archive/2006/04/24/443757.aspx#4271926</link><pubDate>Mon, 01 Oct 2007 17:29:52 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:4271926</guid><dc:creator>Sam</dc:creator><author>Sam</author><description>&lt;p&gt;How can i get the Identity for the last updated record?&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=4271926" width="1" height="1"&gt;</description></item><item><title>re: How to get an Identity value with SQL Server 2005</title><link>http://weblogs.asp.net/esanchez/archive/2006/04/24/443757.aspx#1449766</link><pubDate>Mon, 22 Jan 2007 14:54:02 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:1449766</guid><dc:creator>Kjetil</dc:creator><author>Kjetil</author><description>&lt;p&gt;Any idea on how to use this in conjunction with ADO.NET? Using the old &amp;quot;scope_identity()&amp;quot; and return value from stored procedure, one could simply map this to a SqlDataSource object using e.g. an InsertParameter with Direction=&amp;quot;Output&amp;quot;. But I don't see any way to accomplish this using the new output clause in SQL Server 2005....&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=1449766" width="1" height="1"&gt;</description></item><item><title>re: How to get an Identity value with SQL Server 2005</title><link>http://weblogs.asp.net/esanchez/archive/2006/04/24/443757.aspx#443935</link><pubDate>Tue, 25 Apr 2006 11:13:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:443935</guid><dc:creator>Mike Wood</dc:creator><author>Mike Wood</author><description>Okay, whoops.  I need to read more, the author does point out Scope_Identity is better to use.  Sorry about that.&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=443935" width="1" height="1"&gt;</description></item></channel></rss>