My primary indexes are unique reference numbers like 002345 and 000023.
If I format them as integers I loose my zero’s. They need to be 6 digits.
Can I use CHAR? I don’t need any auto increments.
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.
Yes, you can use a
CHARcolumn as a primary key in MySQL.However you should consider keeping your reference numbers as integers and applying the leading 0s at the application level.
You may also want to consider using a surrogate key that is not derived from the reference number or any other application data. The main advantage would be that your records won’t lose their “handle” if the order reference number ever changes. You will also get the additional performance of an integer index as a positive side-effect.