MySql:: if field is primary key + auto increment should he also defined as unsigned or mysql doing that by default?
Edit:
- I asking because integer unsigned save 2* space vs integer.
- I asking about INNODB.
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
MySQL does not make auto increment fields unsigned by default, and you can keep it signed if you like.
The consequence of auto increment is that MySQL keeps a counter for this table which is increased whenever you insert a row without specifying a value for the identity column, and the current value is used as a default for that column. However, if you explicitly specify a value for the identity column on insert, the auto increment status will remain untouched. If the column is of a signed type, this means that you can insert negative values as the ID. In most cases however, you want to let MySQL handle auto increment values completely.
Of course, due to the primary key constraint, the insert will still fail if you try to insert identity values that are in use already, because a primary key also implies a unique constraint.