This is a general question. How can I avoid duplicate entries in some database tables? I am implementing a books database which has table for books, which references a table with authors and a table with publishers. Currently, for example, the publishers gets generated with duplicate values. For example:
id name
1 Addison-Wesley
4 Addison-Wesley
7 Addison-Wesley
Same for authors.
I would like that duplication is avoided and there would be only one entry for Addison-Wesley
forever:
id
1 Addison-Wesley
I am using MySQL database. And this is a Spring Boot application with JPA dependencies. Do I have to programmatically check for duplicates? For example, in the above Publishers, I could check if "name" is in the database and thus avoid inserting it to the database table?