Prev | Current Page 131 | Next

Emilian Balanescu and Cristian Darie

"Beginning PHP and MySQL E-Commerce: From Novice to Professional, Second Edition"


Primary Keys
The way you work with data tables in a relational database is a bit different from the way you
usually work on paper. A fundamental requirement in relational databases is that each data
row in a table must be uniquely identifiable. This makes sense because you usually save records
into a database so that you can retrieve them later; however, you can??™t always do that if each
table row doesn??™t have something that makes it unique. For example, suppose you add another
record to the department table shown previously in Figure 4-6, making it look like the table
shown in Figure 4-7.
Figure 4-7. Two departments with the same name
Look at this table, and tell me the description of the Seasonal department! Yep, we have
a problem??”we have two departments with the same name Seasonal (the name isn??™t unique).
If you queried the table using the name column, you would get two results. Sometimes getting
multiple results for a query is what you expect??”but other times you want the rows to be uniquely
identifiable depending on the value of a column, which is supposed to be unique.
This problem is addressed, in the world of relational database design, using the concept
of the primary key, which allows you to uniquely identify a specific row out of many rows.
Technically, the primary key is not a column itself. Instead, the PRIMARY KEY is a constraint that
when applied on a column guarantees that the column will have unique values across the table.


Pages:
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
Rowy noclegi męskie skarpetki rowerowe wycieczki do Skandynawii pity mapa Niemiec