Yes, this is redudant. We dont have to state the ID value, because it will be issued automatically. Actually, it is even a bad idea to state the value we want inserted, because the DBMS shall care about which ID to issue, which can be important in situations when different sessions enter data concurrently.
AUTO_INCREMENT
is MySQL syntax. We can redudantly state the ID value, such as in
INSERT INTO Books (Id, Title) VALUES (3, 'The Catcher in the Rye');
The next ID automatically issued will then be a 4, as can be seen here: dbfiddle MySQL.
In PostgreSQL this used to be SERIAL
instead of AUTO_INCREMENT
. After above insert statement, the next automatically issued ID would still be the 1. This could lead to problems of course, as the next one would be the 2, then the 3, but the 3 would already be inserted manually. Please see: dbfiddle PostgreSQL SERIAL.
In Oracle as of version 12 and in PostgreSQL as of version 10 we can use GENERATED BY DEFAULT AS IDENTITY
to get the same behavior as with PostgreSQL's SERIAL
: dbfiddle Oracle BY DEFAULT, dbfiddle PostgreSQL BY DEFAULT. Or we can use GENERATED ALWAYS AS IDENTITY
so as to forbid the user stating a value for the ID altogether: dbfiddle Oracle ALWAYS, dbfiddle PostgreSQL ALWAYS. This is my favorite. Auto-IDs should be issued automatically, not by the user. It is good that the DBMS is able to detect this and prevent potential problems thus.