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
 select query

Author  Topic 

chiragvm
Yak Posting Veteran

65 Posts

Posted - 2007-09-26 : 07:19:06
hi to all
i want to one select query witch is return me one number

in my database one auto generate field

i want to know what is the next auto generate number in next record?

ex
i will try in max + 1 but is not working when i delete last record

in table 4 record 1,2,3,4
so next record is 5 but i delete 4th record and try
so it return 4 instead of 5

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-09-26 : 07:24:11
Something very similar to

DBCC CHECKIDENT(Table1, RESEED)



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-09-26 : 08:30:51
When you use identity column, you dont need max + 1
Use Scope_identity()

Madhivanan

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

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2007-09-26 : 09:12:21
i want to know what is the next auto generate number in next record?


who cares what the NEXT one is? SQL SERVER is going to insert it, NOT you or the client application.

Like Madhi said, Scope_identity() will return the id that was inserted (current ID).


[Signature]For fast help, follow this link:
http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx
Learn SQL
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2007-09-26 : 09:16:53
Steady cowboy, the way I read it:

The OP is asking the question that Madhi has answered, and not the one YOU think the OP is asking
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2007-09-26 : 09:19:01
I thought the answer was DROP DATABASE

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-09-26 : 09:30:22
quote:
Originally posted by X002548

I thought the answer was DROP DATABASE

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam








Madhivanan

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

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2007-09-26 : 12:45:08
Funny Kristen, I thought we answered the same question. I just interjected a question of "Who cares what the max is" since it does not matter in the least.

[Signature]For fast help, follow this link:
http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx
Learn SQL
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2007-09-26 : 15:06:58
"since it does not matter in the least"

I think it matters a lot if English is the OP's second language and what they mean is "What is the ID for the record I inserted" but phrased it as "What is the ID for the record I am just about to insert".

Jumping to conclusions is a bit easy in here, and I'd like to just remind folk that a) English may not be the first language of posters and b) this particular forum is "New to SQL Server"

Personally, my generous nature does not apply to the obvious Twits and Arrogant people we get here, nor those abusing the generous nature of all those posting and giving their time for free by wanting their Homework answered with no effort on their part, etc.

But can I suggest a "Take a deep breath first" stance please?

Kristen
Go to Top of Page

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2007-09-27 : 07:40:04
Nope. I usually post before the first cup of coffee. That makes for shortness of patience

[Signature]For fast help, follow this link:
http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx
Learn SQL
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page
   

- Advertisement -