More About Entity Is/Is Not Associated With a Database Object

There are several issues to consider when deciding how to create your entities and associate them with database objects. When creating an entity, how do you decide whether it should be represented by a table or by one or more fields? The Pubs database and sample project, Pubs.eqp, present a good example of the considerations to make when designing your project.

Consider the entity book. There are two things in the Pubs database that you might imagine represent books. The first thing you might consider is the title field in the Titles table. This is a good guess. In fact, if you told Microsoft English Query that books are represented in the database by this field, almost all questions work correctly.

You can ask "list the books" and get a list of the contents of this field. You can ask, "Show the authors and their books," and you get the right list. You can even ask, "Who wrote The Gourmet Microwave" and get the right answer. If you ask for counts of books, however, it is possible to get the wrong answer. Why? Well, consider the following question: "How many books were published by New Moon Books?" English Query will build SQL that counts the number of titles published by that publisher. You'd get the correct answer, unless there happens to be more than one book with the same title. In this case, the answer won't include these duplicate titles.

So, it is actually incorrect to say that the title field in the Titles table represents books. In fact, the entire Titles table represents books because each unique row in the table represents a single book. The field title, on the other hand, represents the titles of the books, not the books themselves.

Sometimes, there is an entity in your domain that is not represented explicitly in the database at all.  Consider the question, "Do readers like The Gourmet Microwave?" To make questions like this work, you need to create a relationship containing the phrasing, readers like books (presumably with some SQL condition like titles.ytd_sales>100000). To create this phrasing, you must first create the entity reader. Because there is no list of readers in the database, you simply create an entity not represented by a database object. 


(c) 1996-1998 Microsoft Corporation. All Rights Reserved.