pf » Use Char instead of Varchar to Store UUID's
February 16, 2007
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
Permalink | Add Comment |
add to del.icio.us
| Tags: varchar, char, sql, databases, createuuid, uuid
add to del.icio.us
| Tags: varchar, char, sql, databases, createuuid, uuid
Related Entries
- 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
- SQL to Select a random row from a database table - September 14, 2005
- Insert Delayed with MySQL - August 2, 2005
Trackback Address: 626/AC7AB70DC80071CFC039692BD3380691
Comments
On 01/18/2008 at 1:22:09 PM MST Daniel wrote:
1
UUIDs are always 36 characters long, and not 35. Look up the standard.
- CFSCRIPT Cheatsheet
- 3 New Image Effects for ColdFusion 8
- Googlebot to Submit Web Forms
- ColdFusion 8 Update 1 Fixes some Image Processing Quirks
- 10 Most Useful Image Functions in ColdFusion 8
- Speaking at NYC CFUG This Week
- Adobe AIR Tutorial for HTML / JavaScript Developers
- INFORMATION_SCHEMA Support in MySQL, PostgreSQL
Subscribe to my RSS Feed:
RSS
RSS
Pete Freitag is a software engineer, and web developer located in










