G
Guest
Is there an equivalent class function in C# to generate sequencial guid just
like the NewSequentialID() function in SQL Server 2005?
like the NewSequentialID() function in SQL Server 2005?
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Michael Nemtsev said:Hello Nicholas Paldino [.NET/C# MVP],
hmm, awesome But why MS desided make guids sequential? Are there any
practical reasons for this?
N> Roy,
N> N> You can use the UuidCreateSequential API function through the
N> P/Invoke layer.
N> N> For more info, check out the entry on pinvoke.net:
N> N> http://www.pinvoke.net/default.aspx/rpcrt4/UuidCreateSequential.html
N> N> Hope this helps.
N> N>---
WBR,
Michael Nemtsev :: blog: http://spaces.live.com/laflour
"At times one remains faithful to a cause only because its opponents do
not cease to be insipid." (c) Friedrich Nietzsche
Michael Nemtsev said:Hello Nicholas Paldino [.NET/C# MVP],
hmm, awesome But why MS desided make guids sequential? Are there any
practical reasons for this?
Peter said:Michael Nemtsev said:Hello Nicholas Paldino [.NET/C# MVP],
hmm, awesome But why MS desided make guids sequential? Are there any
practical reasons for this?
One common use of sequential GUIDs is when you have a bunch of COM objects
that are all related and you want an easy way of organizing them. Even if
all that means is that they show up next to each other in the registry,
that's sort of useful. There may also be some purpose to being able to
quickly convert from a GUID to a 0-based index.
I suppose one could debate the exact degree of benefit from that sort of
thing, but the fact remains that those are possible reasons for wanting GUID
in sequential order.
Nicholas Paldino said:Michael,
They didn't decide to make them sequential, they just gave an
opportunity to generate them should people need them? I would NOT use
these if I needed to create a unique number, but only if I needed to
create a sequential 128-bit number.
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)
Michael Nemtsev said:Hello Nicholas Paldino [.NET/C# MVP],
hmm, awesome But why MS desided make guids sequential? Are there any
practical reasons for this?
N> Roy,
N> N> You can use the UuidCreateSequential API function through the
N> P/Invoke layer.
N> N> For more info, check out the entry on pinvoke.net:
N> N>
http://www.pinvoke.net/default.aspx/rpcrt4/UuidCreateSequential.html
N> N> Hope this helps.
N> N>---Is there an equivalent class function in C# to generate sequencial
guid
just
like the NewSequentialID() function in SQL Server 2005?
WBR,
Michael Nemtsev :: blog: http://spaces.live.com/laflour
"At times one remains faithful to a cause only because its opponents do
not cease to be insipid." (c) Friedrich Nietzsche
Sericinus hunter said:Peter said:Michael Nemtsev said:Hello Nicholas Paldino [.NET/C# MVP],
hmm, awesome But why MS desided make guids sequential? Are there any practical reasons for this?
One common use of sequential GUIDs is when you have a bunch of COM objects that are all related and you want an easy way of
organizing them. Even if all that means is that they show up next to each other in the registry, that's sort of useful. There
may also be some purpose to being able to quickly convert from a GUID to a 0-based index.
I suppose one could debate the exact degree of benefit from that sort of thing, but the fact remains that those are possible
reasons for wanting GUID in sequential order.
Also, having a clustered index on GUID column in the database table
makes more sense if it is sequential.
Dave said:Hi,
I don't think so. I thought the point of a clustered index was to order the data rows against the index. The index is sorted no
matter the type of the column or the values that it contains.
Dave said:Hi,
I don't believe that it makes more sense to have sequential guids as the values in your column, however I do believe it's required
to have the values sorted in a clustered index. Because of that requirement the DBMS will sort on your column, so I don't think it
really matters whether the values appear sequentially in the table.
In SQL Server, there is no mention in the documentation about sequential guids and there is no function AFAIK that will create them.
When inserting rows into the table with that column, one usually uses the newid() function to populate it, which does not produce
sequential guids.
When you create a unique clustered index on a uniqueidentifier column the index will sort on the values in that
column, and because of its clustered nature, the data rows will be sorted based on the sort of the index.
There is. They introduced it with SQL Server 2005.
And now you can use newsequentialid() function. Although it works only
in default constraint declarations.
Yes, but here how it works during inserts. With clustered index,
the data row must physically go to right place in the storage because,
as you correctly said, the whole row, i.e the data itself is sorted.
Now imagine that a new row is inserted and its GUID value is somewhere
in the middle of the range of already existing (and sorted) rows. This
is very likely due to random nature of GUID. The row goes in the middle,
and all the rows from that point to the end must be physically rearranged
on the disk. Performance-wise this can be very costly. With sequential
GUID on the other hand, you always add the row to the end of physical
storage, thus making inserts much more effective.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.