what to do with this database? [closed]
I prepared a SQL fiddle where you can check the results: http://sqlfiddle.com/#!9/c0ae78b/1
The table may look something like this:
CREATE TABLE books (
isbn VARCHAR(32) PRIMARY KEY,
title varchar(64) NOT NULL,
genre varchar(64) DEFAULT NULL,
author varchar(64) DEFAULT NULL,
counter INT NOT NULL DEFAULT 1);
Of course, you need to tweak field lengths and nullability of all fields to your needs. ISBN field, as it is a primary key, cannot be nullable.
To comment on it a little bit - ISBN is a perfect primary key in this example. Every other book has a different ISBN number. Having this set up the only thing you have to remember about is to add ON DUPLICATE KEY UPDATE
clause in all your INSERT queries. In our case, it would be
INSERT INTO books (isbn, title) VALUES ('code-book-1', 'star wars'), ('code-book-1', 'star wars') ON DUPLICATE KEY UPDATE counter = counter + 1;
Instead of returning an error with a primary key collision value in the counter
field will be increased by one.