Mysql – Zerofill Auto Increment – theSql

database-designMySQL

Ok,

So I'm working on an app and I can't remember, for the life of me, why I set a zerofill on an Auto_Increment column when I created the database. And I couldn't exactly find any compelling info while searching as to why I'd use or not use zerofill on this column.

After all, it does not affect the data in the filed (or the int value), it is just for formatting sake.

So, I figured I would get your take on this matter.

Why Use (or not Use) Zerofill on an Auto_Increment field (or for that matter any int field).

Best Answer

I have only seen one instance where this made a difference. The int was being cast as a string, and then sorted alphabetically. The zero fill prevented a strange sort order, such as 10 coming before 9.