views:

521

answers:

1

I was using the SDK for CRM, and printed out the PK on a bunch of instances of one of our entities. I repeated it with the database's filtered views, and got the same answer:

    1a6c691d-391a-de11-8b0e-0050568407cb
    bd7b0ff0-391a-de11-8b0e-0050568407cb
    ed272bfe-391a-de11-8b0e-0050568407cb
    ... and so on ...

These don't appear to be valid GUIDs. For one, they LOOK wrong - they're nearly identical, a property that GUIDs haven't had since the old version 1 & 2 GUIDs that were based on MAC addresses and clock time. Moreover, however, is the fact that a certain nibble in a GUID indicates the GUID's version - that nibble is incorrect here. (First nibble of the third section, ie: 1a6c691d-391a-de11-8b0e-0050568407cb) - valid values are 1-5) (Generate a GUID using MS's GUID Generator - that slot will always be 4. (At least for the version I have.))

Are these GUIDs, or just IDs, and how do I know?

+3  A: 

You are right that they are GUIDs and that they are sequential. These keys are not generated by CRM. They are generated by SQL Server.

SQL Server has a GUID type called uniqueidentifier. It can be configured as either NEWID() or NEWSEQUENTIALID(). NEWID() will generate a new GUID every time. NEWSEQUENTIALID() generates a GUID the first time and then sequentially increments it on subsequent database inserts.

So you have discovered that Dynamics CRM is configured for NEWSEQUENTIALID().

More info about this is here: http://www.mssqltips.com/tip.asp?tip=1600

David McDonald
Wow, thanks. I wasn't sure I was ever going to get a straight answer to that one. Did some more research and found this: http://www.fotia.co.uk/fotia/DY.19.NewSequentialId.aspx - seems that they can be called GUIDs since they have your MAC in them.
Thanatos
Interesting article, thanks for posting it. It explains why CRM uses the NEWSEQUENTIALID() - because of the db perf benefits.
David McDonald