Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
PHP Programming With MySQL Second Edition.doc
Скачиваний:
0
Добавлен:
01.05.2025
Размер:
43.07 Mб
Скачать

Introduction to Databases

385

Figure 7-3

Table with redundant information

A one-to-many relationship provides a more efficient and less redun-

dant method of storing this information in a database. Figure 7-4

shows the same information organized into a one-to-many

relationship.

CHAPTER 7

Working with Databases and MySQL

386

Figure 7-4

One-to-many relationship

In some

databases,

the table

containing

multiple

records for one entity (for

example, the program-

ming language table in

Figure 7-4) is the primary

table. In these cases, the

relationship is often

referred to as a many-to-

one relationship.

In Figure 7-4, the tables are not normalized because the language

field contains duplicate values. Recall that primary and foreign keys

are the only pieces of information in a relational database that should

be duplicated. To further reduce repetition, you could organize the

Languages table in Figure 7-4 into another one-to-many relationship.

However, a better choice is to create a many-to-many relationship,

which exists in a relational database when many records in one table

are related to many records in another table.

Consider the relationship between programmers and programming

languages. Each programmer can work with many programming

languages, and each programming language can be used by many


Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]