Jump to content

newbie question


jimfog

Recommended Posts

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...