Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1188
  • Last Modified:

MySQL varchar datatype -- what is meant by varchar(30)?

In MySQL, when a field is defined as a varchar(30) data type, what exactly does this mean?  What is the maximum number of characters this field can hold?  Thanks!
0
sah18
Asked:
sah18
  • 2
  • 2
  • 2
  • +1
3 Solutions
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
yes, the 30 indicates the maximum capacity
0
 
hongjunCommented:
And if you only use 10 characters, the remaining 20 will not be wasted. you only use 10 instead of 10+20 in this case.
0
 
sah18Author Commented:
so, that is the *var* part, that it will only store exactly what is used?  but the max is still set at whatever I give as a parameter (30 in this case)?
0
Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

 
hongjunCommented:
yes.
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
yes, exactly.
if you used CHAR(30), it would use 30 characters all the time, padding right with spaces
0
 
LowfatspreadCommented:
varchar(30)  will allow you store up to 30 characters in the column , using only as much space as you actually supply the column with characters for..

in storage terms there will be an additional overhead to also store the length of the data  (1 0r 2 bytes)

normally if your data sizes vary by only 10 characters  e.g. 30 character max  average number of characters in use  22... then you should use a fixed length datatype e.g. char(30) to avoid the overheads of maintaing the length/size of the data...

hth    
0
 
sah18Author Commented:
Thanks to everyone!
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now