Primary Keys: The very Special id Field¶
Check out that id column. Our INSERT query sent values for name and breed, but not id. That’s allowed, and you can even setup a column to have a default value, just for that situation.
But every table has one special column called the primary key. This column is usually an integer that auto-increments. If we don’t send a value for it, MySQL just picks 1, 2, 3, 4 and so on. That’s really handy, because the primary key of each row needs to be unique in the table.
Let’s add another pet, but leave both the id and breed columns blank:
INSERT INTO pet (name) VALUES ("Pico de Gato");
Use SELECT to see all 3 rows:
SELECT * FROM pet;
The id column just keeps on auto-incrementing, but this breed is empty. What are you Pico do Gato?