Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 how can I find the current value of a auto increme

Author  Topic 

SDC
Starting Member

3 Posts

Posted - 2010-01-20 : 08:17:43
how can I find the current value of a auto increment field in sql server 2008.
I used max function but there are some limitations.Suppose I delete two rows. then if I use MAX() function it will show the max value of the the field, not the deleted rows value(it's lost). Now I want the new value that is generated.
any help Plz.

Thanks.

svicky9
Posting Yak Master

232 Posts

Posted - 2010-01-20 : 08:30:54
IDENT_CURRENT ('TableName')

http://msdn.microsoft.com/en-us/library/ms175098.aspx

http://www.sqlserver007.com
Go to Top of Page

SDC
Starting Member

3 Posts

Posted - 2010-01-20 : 08:42:27
I used IDENT_CURRENT() .

Then I increment the value by 1 to find the value that will be used if I insert a new row. OK that will solve my problem. Thanks

But May I know why I shall use
use SET NOCOUNT ON

Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2010-01-20 : 13:15:15
You are not able to find what value will be given to a row that you are about to insert. Another user may make an INSERT just after you check IDENT_CURRENT() and before your INSERT happens.

What you can find is the identity value that your row was given immediately after you insert it by checking "scope_identity()"

"But May I know why I shall use
use SET NOCOUNT ON
"

I can't see that that is relevant to your question, I'm afraid. Maybe divyaram can clarify?
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-02-04 : 04:39:34
quote:
Originally posted by divyaram

use SET NOCOUNT ON


Regards,
Divya


Some of your recent answers add no value to the questions
Did you read the questions properly?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -