Reputation: 1467
I have a table where I want to have a unique identifier that is the same across database instances which I can reference in my code. The table is very unlikely to have > 500 rows. Is there a difference between using a GUID and using an NVARCHAR(6) populated by LEFT(NEWID(),6) as the identifier; assuming of course that the field is marked as a PK and is unique.
The ID is going to be used in a custom control and I think that:
<cc1:mycontrol id="test" runat="server" code="71E29D" />
Is more readable than and easier to use than:
<cc1:mycontrol id="test" runat="server" code="71E29D4C-A00A-4F1A-9785-08D030A9B764" />
Upvotes: 1
Views: 304
Reputation: 12613
Be aware of different GUID generation schemes. In some cases, a lot of the bytes are not random, but based of MAC addresses and other such system stuff. That could mean that your first 6 characters will always be the same...
Upvotes: 3
Reputation: 44316
By truncating the GUID, you may end up with duplicates. Just use the GUID. ( or come up with another scheme for shorter unique IDs)
Upvotes: 2
Reputation: 160
GUIDs aren't supposed to be readable really. They are used to ensure uniqueness of IDs. If you use only a portion of a GUID, officially it cannot be guaranteed to be unique. Consider having a pair, I've had a GUID as the my rowId and then a second column to be some readable value.
Upvotes: 2