Should you specify column types in MySQL exactly?

When I define columns in MySQL, I usually use int, varchar (255), text, and random enumeration for boolean. What are the benefits of accurately specifying column types, rather than just their maximum?

For example, a password field encoded as MD5 will never exceed 32 characters, is there any tangible performance boost from using varchar (32) to varchar (255)?

+3
source share
5 answers

Per manual , a VARCHAR(N)given actual length, takes up the same amount of space for any N up to 255, so using 32 does not require free space. But there is an advantage to the clarity and readability of your circuit in using the type that best matches the evidence.

+4
source

I agree with what Clyde says, but your example password is not particularly good. Since the sum of MD5 should ALWAYS be 32 characters, you can use CHAR (32) instead of VARCHAR (32), which in many cases will be faster / more efficient.

+2
source

, . -. , int, char ( ) .

, 100 . , . varchar .

, , -/.

+2

, / , . , .

, , db, . , : ", 100 , ". , , , varchar (255), .

+1

255 50 - .

In SQL Server, I will take care to put my name, address, etc. in NVarCharso that I can internationalize when necessary. I have a phone number that can store more than 10 digits in the USA.

+1
source

Source: https://habr.com/ru/post/1712211/


All Articles