Why do I need to have a primary key on my database for it to function correctly? In every tutorial I read, you need to make the id key the primary key. What does the primary key do differently than the regular cells?
Keys are for identification and data integrity. A key defines how tuples (rows) in a table can be uniquely identified. The integrity of keys is assured because the DBMS prevents users from entering duplicate information into the table. Database users can therefore rely on the keys to identify in the real world the things recorded in the database.
A "primary" key is fundamentally no different from any other candidate key in the same table. It's just a convention used to designate one key per table as significant in some way. Usually it is the "preferred" or "most important" key of a table and the one used in foreign key references.
You allude to tutorials but provide no example. Consider the following two tables that have what I understand to be an "id key" (noting the question has the
Does either table have a usable key? I would say no. So my first answer is that
Reading between the lines, I think the question effectively asks
to which my second answer is, seek out a better tutorial!
|show 9 more comments|