CHAR() or VARCHAR() as primary key in an ISAM MySQL table?

后端 未结 4 1954
无人共我
无人共我 2020-12-10 16:31

I need a simple table with a user name and password field in MySQL. Since user names must be unique, it makes sense to me to make them the primary key.

Is it better

4条回答
  •  隐瞒了意图╮
    2020-12-10 16:56

    I don't see CHAR used much in any MySQL databases i've worked on. I would go with the VARCHAR

    For a CHAR(30) for example, the entire 30 characters are stored in the table meaning every entry will take up the same space, even if your username is only 10 characters long.

    Using VARCHAR(30) it will only use enough space to store the string you have entered.

    On a small table it wont make much difference, but on a larger table the VARCHAR should prove to keep it smaller overall.

提交回复
热议问题