Use Char instead of Varchar to Store UUID's
I know a lot of developers like using UUID's for primary keys instead of integers. But one thing I see alot is the use of the varchar datatype to store these strings.
If your using ColdFusion's CreateUUID() function to generate a unique identifier, you will notice that it always returns a 35 character string. So why store it in a variable length column in the database? Instead of using varchar (35) you can simply use char (35).
As a rule, if you are storing a fixed length string in a database use char rather than varchar. A varchar will have an extra byte of overhead on most databases (usually an integer stating the actual length of the string).
Some other common places where you should use char over a varchar include:
- Two Character US State Codes
- Two Character Country Codes
- One Character Status Flags
Tweet
add to del.icio.us
| Tags: varchar, char, sql, databases, createuuid, uuid
Related Entries
- Use varchar(max) instead of text in SQL Server - December 9, 2009
- Cheat Sheet for SQL Server - April 20, 2009
- Sphinx - Open Source SQL Full Text Search Engine - November 1, 2006
- Updated SQL Reserved Words Checker - March 28, 2006
- MySQL FULLTEXT Indexing and Searching - September 29, 2005
Trackbacks
Comments
That said, thanks Pete for sharing this. I first ran across using UUID looking at Ray C.'s apps recently.
Post a Comment
Recent Entries
- Nginx redirect www to non www domain
- HashDOS and ColdFusion
- HackMyCF Updated for APSB11-29 Security Hotfix
- Adobe eSeminar on FuseGuard
- Determining Which Cumulative Hotfixes are Installed on ColdFusion
- Adding Two Factor Authentication to ColdFusion Administrator
- ColdFusion Developer Week at Adobe.com
- Bug Loading Scripts for CFFileUpload and CFMediaPlayer





