Tutorial Data Modeling For A Small Database
Tutorial Data Modeling For A Small Database
Database
In this tutorial, you will use SQL Developer Data Modeler to create models
for a simplified library database, which will include entities for books,
patrons (people who have library cards), and transactions (checking a
book out, returning a book, and so on).
This tutorial uses the same entities as for the tutorial provided with the
SQL Developer online help. The model is deliberately oversimplified and
would not be adequate for any actual public or organizational library. For
more advanced tutorials and other materials, see Section 1.9, "Additional
Resources for Data Modeling".
If the instructions do not mention a particular dialog box, tab, or field,
then do not specify anything for it.
This simplified tutorial uses only a subset of the possible steps for the TopDown Modeling approach. (For information about the approaches, see
Section 1.4, "Approaches to Data Modeling".)
You will perform the following major steps:
1. Develop the Logical Model.
2. Develop the Relational Model.
3. Generate DDL.
4. Save the Design.
In planning for your data needs, you have determined that several kinds
of fields will occur in multiple kinds of records, and many fields can share
a definition. For example, you have decided that:
You therefore decide to add appropriate domains, so that you can later
use them to specify data types for attributes when you create the entities.
(These added domains will also be available after you exit Data Modeler
and restart it later.)
1. Click Tools, then Domains Administration.
2. In the Domains Administration dialog box, add domains with the
following definitions. Click Add to start each definition, and click
Apply after each definition.
Name
Logical Type
Other Information
Person Name
VARCHAR
Size: 25
Address Line
VARCHAR
Size: 40
City
VARCHAR
Size: 25
State
VARCHAR
Size: 2
Zip
VARCHAR
Size: 10
Book Id
VARCHAR
Size: 20
Numeric Id
NUMERIC
Precision: 7, Scale: 0
Title
VARCHAR
Size: 50
3.
4. When you have finished defining these domains, click Save. This
creates a file named defaultdomains.xml in the domains
directory (folder) under the location where you installed Data
Modeler.
5. Optionally, copy the defaultdomains.xml file to a new location
(not under the Data Modeler installation directory), and give it an
appropriate name, such as library_domains.xml. You can then
import domains from that file when you create other designs.
6. Click Close to close the dialog box.
7. Go to Section 2.1.2, "Creating the Books Entity".
Datatype
book_id
Domain: Book Id
title
Domain: Title
author_last_na
me
Name
Datatype
author_first_na
me
rating
6.
7. Click OK to finish creating the Books entity.
8. Go to Section 2.1.3, "Creating the Patrons Entity".
Type
patron_id
last_name
Domain: Person
Name
Attribute
Name
first_name
Type
Domain: Person
Name
city
Domain: City
state
Domain: State
zip
Domain: Zip
location
Structured type:
SDO_GEOMETRY
6.
7. Click OK to finish creating the Patrons entity.
8. Go to Section 2.1.4, "Creating the Transactions Entity".
5. Click Attributes on the left, and use the Add (+) icon to add the
following attributes, one at a time. (For datatypes, select from the
Domain types, except for transaction_date, which uses a Logical
type.)
Attribute
Name
Type
transaction_id Domain:
Primary UID (unique identifier). (Unique
Numeric Id transaction ID number)
patron_id
Domain:
M (mandatory, that is, must not be null).
Numeric Id Must match a patron_id value in the Patrons
entity.
book_id
Domain:
Book Id
transaction_d
ate
Logical
type:
Datetime
transaction_ty Domain:
M (mandatory, that is, must not be null).
pe
Numeric Id (Numeric code indicating the type of
transaction, such as 1 for checking out a
book.)
6.
7. Click OK to finish creating the Transactions entity.
8. Go to Section 2.1.5, "Creating Relations Between Entities".
Create the relationships as follows. When you are done, the logical model
pane in the main area should look like the following figure (using Bachman
notation, which you can change to Barker by clicking View, then Logical
Diagram Notation, then Barker Notation):
1. In the logical model pane in the main area, arrange the entity boxes
as follows: Books on the left, Patrons on the right, and Transactions
either between Books and Patrons or under them and in the middle.
(If the pointer is still cross-hairs, click the Select icon at the top left
to change the pointer to an arrow.)
Suggestion: Turn off auto line routing for this exercise: right-click in
the Logical pane, and ensure that Auto Route is not checked.
2. Click the New 1:N Relation icon.
3. Click first in the Books box, then in the Transactions box. A line with
an arrowhead is drawn from Books to Transactions.
4. Click the New 1:N Relation icon.
5. Click first in the Patrons box, then in the Transactions box. A line
with an arrowhead is drawn from Patrons to Transactions.
6. Optionally, double-click a line (or right-click a line and select
Properties) and view the Relation Properties information.
7. Go to Section 2.2, "Develop the Relational Model".