Unique Identifier
-
Friday, March 02, 2012 12:28 PM
Hi all
I have a table with an Id column which is the primary Key. Is there a script that I could use to find out the next Id number before I insert into the next row.
All help appreciated as usuall
Thank you
Richard...
All Replies
-
Friday, March 02, 2012 12:32 PM
Is this column an IDENTITY column then you use the IDENT_CURRENT().
http://msdn.microsoft.com/en-us/library/ms175098.aspx
if not the you need to issue a select stmt to find the value.
select max(id) curretValue from yourtable
VT
Please mark answered if I've answered your question and vote for it as helpful to help other user's find a solution quicker
- Marked As Answer by RichIEvans Friday, March 02, 2012 12:55 PM
-
Friday, March 02, 2012 12:37 PM
Hi,
you cannot find out what id the system would generate next. The problem here is, that the unique identifiers are generated out of multiple factors including the time. So you can ask the database to generate a new id and then insert it but you cannot get the next id that will be calculated at an unknown time later. Please see http://en.wikipedia.org/wiki/Globally_unique_identifier for more details about the unique identifier.
To get a new id, you can simply call NEWID:
http://msdn.microsoft.com/en-us/library/ms190348.aspxWith kind regards,
Konrad
- Marked As Answer by RichIEvans Friday, March 02, 2012 12:55 PM

