In the Library you will meet three kinds of catalog. They look similar but differ in the strictness of their rules. Let us learn them from the strongest.
This is the strictest catalog - the main catalog number of every scroll. Its rules:
NULL values.Most often it is the
id column. It uniquely points to a row, like a scroll's catalog number.1SELECT * FROM autorzy WHERE id = 3;A little looser. It also guards uniqueness, but:
NULL values (in MySQL there can be many of them).Ideal for columns like
email - every address different, but the table already has its primary key elsewhere.The gentlest catalog. It does not guard uniqueness - it allows repetitions. Its only job is to speed up searching.
It works great on the
autor_id column in the ksiazki table - one author can have many books, so the values repeat, but we want to find them quickly.| Kind | Unique? | NULL? | How many per table | |------|---------|-------|---------------------| | PRIMARY KEY | yes | no | one | | UNIQUE | yes | yes | many | | INDEX | no | yes | many |
Remember: all three speed up reading, but only the first two enforce uniqueness.