1

I want to store "First name" with max length of 12 characters. If it exceeds, it will be rejected.

So, I create a table with this schema

create table Tb (firstName varchar(12) character set utf8 NOT NULL)

Now if the name is in ASCII, then it will be fine. But what if it's in Japanese or Thai? Each Unicode char takes 3 bytes, so do I need to triple the size like this?

create table Tb (firstName varchar(36) character set utf8 NOT NULL)

But then, if I triple the size like that, then the English users can put a name that is longer than 12 chars. How to solve this issue?

Andrew T.
  • 4,701
  • 8
  • 43
  • 62
Tum
  • 3,614
  • 5
  • 38
  • 63
  • Why don't you validate the input before inserting to the DB? – Andrew T. Sep 23 '14 at 10:13
  • 1
    *How to solve this issue?* - **Is it** really an issue? My full first name has 14 ASCII characters. If I can't fill out my first name in a textfield used for online billing, **that** would be a real issue - when the customer is not able to give you his money. – Daniel W. Sep 23 '14 at 10:39
  • maybe this helps http://stackoverflow.com/questions/1997540/mysql-varchar-lengths-and-utf-8 – 1010 Sep 23 '14 at 12:23

1 Answers1

-2

It's always better to use varchar(255) at least when you are not so sure about your field length.

Andrew T.
  • 4,701
  • 8
  • 43
  • 62