jimfog Posted June 4, 2012 Share Posted June 4, 2012 I want to built a table in the db where the user details will be stored, my question has to do with the username column. What type it should be? What I have come to understand it is that it should be of the varchar type. Am I correct? If yes, I would appreciate if someone could explain to me why it should be varchar and not char for example Link to comment Share on other sites More sharing options...
boen_robot Posted June 4, 2012 Share Posted June 4, 2012 The CHAR type is for data which is of a constant length. Like a sha1 hash for example - it's always 40 characters (or 20 if you're storing a binary string). Not more, not less.In contrast, VARCHAR is for data which is not always of a certain length, but is less than or equal to a specified limit. User names fit this category (so you are correct indeed) - you could have a user with a name as short as "jimfog", or a longer one, like "boen_robot".If you use CHAR for data which is of variable length, the extra bytes will also be filled into the DB. With spaces, but still - they'll take space. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now