Lab Session 06: (Relational Modeling)
Lab Session 06: (Relational Modeling)
Lab Session 06
(Relational Modeling)
Database System Lab Sessi
Session 05
Fast NUCES –Department of Computer Science
Logical Models:
The logical model in SQL Developer Data Modeler includes standard logical modeling facilities,
such as drawing entities and relationships etc.
Relational Models:
The SQL Developer Data Modeler relational model is an intermediate model between the logical
model and the physical models. It supports relational design decisions independent of the
constraints of the target physical platform(s). All many-to-many relationships and all super
type/sub-types entity hierarchies are resolved during forward engineering (transformation) of the
logical model, or part of it, to a relational model.
Physical Model:
A physical data model defines all of the logical database components and services that are
required to build a database or can be the layout of an existing database.
A physical data model consists of the table’s structure, column names and values, foreign and
primary keys and the relationships among the tables.
n
Database System Lab Sessi
Session 05
Fast NUCES –Department of Computer Science
n
Database System Lab Sessi
Session 05
Fast NUCES –Department of Computer Science
Creating Entities
Creating the book Entity:
• Create the Books entity as follows:
• In the main area (right side) of the SQL Developer Data Modeler window, click the
Logical tab.
• Click the New Entity icon.
• Click in the logical model pane in the main area; and in the Logical pane press,
diagonally drag, and release the mouse button to draw an entity box. The Entity
Properties dialog box is displayed.
• Click General on the left, and specify as follows:
• Name: Books
• Click Attributes on the left, and use the Add (+) icon to add the following attributes, one
at a time. (For data types, select from the Domain types except for Rating, which is a
Logical type.)
author_last_name Domain: Person Name M (mandatory, that is, must not be null).
n
Database System Lab Session 005
Fast NUCES –Department of Computer Science
last_name Domain: Person Name M (mandatory, that is, must not be null).
25 characters maximum.
state Domain: State (2-letter code for the state where the
patron lives.)
transaction_date Logical type: Datetime M (mandatory, that is, must not be null). Date
and time of the transaction.
n
Database System Lab Session 005
Fast NUCES –Department of Computer Science
n
Database System Lab Session 05
Fast NUCES –Department of Computer Science
3. Generate DDL
Develop the physical model as follows:
1. Optionally, view the physical model before we generate DDL statements:
a. With the Library logical model selected, click Physical, then Open Physical
Model. A dialog box is displayed for selecting the type of database for which to
create the physical model.
b. Specify the type of database (for example, Oracle Database 11g), and click OK. In
the hierarchy display on the left side of the window, a Physical Models node is
added under the Library relational model node, and a physical model reflecting
the type of database is created under the Physical Models node.
c. Expand the Physical Models node under Library (the relational model), and
expand the newly created physical model and nodes under it that contain any
entries (such as Tables and Columns), to view the objects created.
2. Click File, then Export, then DDL File.
n
Database System Lab Session 06
Fast NUCES –Department of Computer Science
3. Select the database type (for example, Oracle Database 11g) and click Generate.
The DDL Generation Options dialog box is displayed.
4. Accept all defaults, and click OK. A DDL file editor is displayed, with SQL statements
to create the tables and add constraints. (Although we can edit statements in this window,
do not edit any statements for this tutorial exercise.)
5. Click Save to save the statements to a .Sql script file (for
example, create_library_objects.sql) on were local system.
Later, run the script (for example, using a database connection and SQL Worksheet in SQL
Developer) to create the objects in the desired database.
6. Close to close the DDL file editor.