June 9, 2005 at 11:56 pm
Hi,
I want to know if there is any unique system global variable identifier for each row returned
in the resultset in sql2000.
Regards,
brlele
June 10, 2005 at 2:34 am
You could use the newid() system function as in:
select newid() [RowId], * from MyTable
The newid() function returns a value of the uniqueidentifier datatype. The uniqueidentifier is a large (16 bytes) datatype, but it's guaranteed to be unique across all machines around the world (which is why it's also called a Globally Unique Identifier or GUID).
Although you can sort on the uniqueidentifier, it is not based on the visible (display) value or on the order in which the values were generated.
Other solutions invloving schema changes or more disk io could be:
- Add Identity columns to your table(s), then use it (them) in the final resultset.
- Use "SELECT INTO" to put the data in a temporary table using the identity Function, then select from the temporary table:
select identity( int, 1, 1 ) [RowId], * into #Temp from MyTable
select * from #Temp
June 10, 2005 at 3:22 am
No, there is no such identifier attached with each row. If you could tell a little more about what you are trying to achieve then there is most probably one or more solutions for it.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply