Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm currently having a discussion in my class about the datatypes char and int in MySQL. We have a phone number of 8 individual numbers. However, we can't find any pros and cons for each of them.

Should we use the char type or the int type, and why?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
699 views
Welcome To Ask or Share your Answers For Others

1 Answer

If you have a fixed size then you can use char(8) -> 8B , mysql works much faster with fixed size fields, but if you chose int -> 4B you will save space and also if you will have a index on that field it will work faster then the char.

You can do a simple benchmark to test the speed of writes and reads using char(8) and int

There is no point in using variable length type like varchar or varbinary if you have a fixed size because performance will decrease


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...