Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GUID: varchar(36) versus uniqueidentifier

I'm working with a legacy database that stores GUID values as a varchar(36) data type:

CREATE TABLE T_Rows (
    RowID    VARCHAR(36) NOT NULL PRIMARY KEY,
    RowValue INT         NOT NULL
) 

INSERT T_Rows (RowID, RowValue) VALUES (NEWID(), 1)

I would assume that storing a GUID as a uniqueidentifier would be preferable since it's only 16 bytes in size as opposed to 36.

Are there any advantages to storing a GUID as a varchar?

like image 812
8kb Avatar asked Aug 19 '10 23:08

8kb


1 Answers

Perhaps only the fact that you can 'read' them from a SELECT statement (although I don't think that's particularly useful as you can use a function in a select to make Uniqueidentifiers displayable).

If the table is large, saving 20 bytes per row is considerable.

like image 165
Mitch Wheat Avatar answered Oct 15 '22 17:10

Mitch Wheat