I am developing a library management software in javafx and I am using sqlite as a database for that. I have to store data of almost 50000 books. And all those books would have a barcode. Obviously, the barcode is a going to be an Integer(PS. Correct me if I am wrong) and it would contain many digits. So I am not understanding whether I should go with sqlite integer datatype or use string datatype for my primary key?

  • It's not obvious that the barcode is an integer. Most types of barcode contain alphanumerical characters.
    – Pieter B
    Dec 30, 2018 at 5:25
  • so what datatype should I use for it? Coz I have searched on the internet that using a string as a primary key is not a good practice. Dec 30, 2018 at 5:33
  • 1
    What type of barcode? These things usually have well defined (common) formats. Without knowing that we can't answer your question.
    – Jan Doggen
    Dec 30, 2018 at 11:00

1 Answer 1


You should look into what kind of barcode the books are using you are going to store. Take a look here for more information about bar codes https://barcode.tec-it.com/en/EAN13?data=978020137962

You should also look into if you need to store leading zeros.

And your primary key does not have to be the value from the bar code.

  • 3
    Upvoted, though I would express the last sentence stronger: it is a pretty good idea to separate primary keys completely from any business logic, since if there is business logic involved, sooner or later there will be requirements to change something in it, which can be a real hassle for PKs. And the constraints for bar codes are definitely business logic. The OP will probably do themselves a favor by using an artificial Book ID, and put the bar code value into a separate column, not part of the PK.
    – Doc Brown
    Dec 30, 2018 at 13:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.