Feb-21-2023, 03:13 AM
Hi,
if the unique constrain fails it typcially means that there is already an entry with the exactly same title. As the title has to be unique, you cannot add another book with the same title. This will happen when you run your codes shown twice.
I would also suggest reconsidering making the title alone unique, as it prevents to have two books with the same title but from different authors in the database. You may want to consider to have a combined unique constrain so that title + author have to be unique.
You also may want to rethink your database design for the book table, as it doesn't take under consideration that a book may be written by two or more authors.
Regards, noisefloor
if the unique constrain fails it typcially means that there is already an entry with the exactly same title. As the title has to be unique, you cannot add another book with the same title. This will happen when you run your codes shown twice.
I would also suggest reconsidering making the title alone unique, as it prevents to have two books with the same title but from different authors in the database. You may want to consider to have a combined unique constrain so that title + author have to be unique.
You also may want to rethink your database design for the book table, as it doesn't take under consideration that a book may be written by two or more authors.
Regards, noisefloor