Maxxus PRO SPK-23 Especificaciones Pagina 202

  • Descarga
  • Añadir a mis manuales
  • Imprimir
  • Pagina
    / 893
  • Tabla de contenidos
  • MARCADORES
  • Valorado. / 5. Basado en revisión del cliente
Vista de pagina 201
written by two coauthors, each of whom had written other books, on their own or possibly with
other authors. This type of relationship usually gets a table all to itself, so you might have Books,
Authors, and Books_Authors. This third table would only contain the keys of the other tables as
foreign keys in pairs, to show which authors have been involved with which books.
How to Design Your Web Database
Knowing when you need a new table and what the key should be can be something of an art.
You can read huge reams of information about entity relationship diagrams and database nor-
malization, which are beyond the scope of this book. Most of the time, however, you can fol-
low a few basic design principles. Lets consider these in the context of Book-O-Rama.
Think About the Real World Objects You Are Modeling
When you create a database, you are usually modeling real-world items and relationships and
storing information about those objects and relationships.
Generally, each class of real-world objects you model will need its own table. Think about it:
We want to store the same information about all our customers. If there is a set of data that has
the same shape, we can easily create a table corresponding to that data.
In the Book-O-Rama example, we want to store information about our customers, the books
that we sell, and details of the orders. The customers all have a name and address. The orders
have a date, a total amount, and a set of books that were ordered. The books have an ISBN, an
author, a title, and a price.
This suggests we need at least three tables in this database: Customers, Orders, and Books.
This initial schema is shown in Figure 7.3.
At present, we cant tell from the model which books were ordered in each order. We will deal
with this in a minute.
Avoid Storing Redundant Data
Earlier, we asked the question: Why not just store Julie Smiths address in the Orders table?
If Julie orders from Book-O-Rama on a number of occasions, which we hope she will, we will
end up storing her data multiple times. You might end up with an Orders table that looks like
the one shown in Figure 7.4.
There are two basic problems with this.
The first is that its a waste of space. Why store Julies details three times if we only have to
store them once?
Using MySQL
P
ART II
176
10 7842 CH07 3/6/01 3:34 PM Page 176
Vista de pagina 201
1 2 ... 197 198 199 200 201 202 203 204 205 206 207 ... 892 893

Comentarios a estos manuales

Sin comentarios