You are on page 1of 12

Assignment Two Chapter 3 Create table statements 55 pts.

For this assignment, we will be taking a look at the Customer Table, Employee Table
and OrderTbl that are in our textbook on page 69. To make things easier, I have
copied an image of the tables to this assignment.

We will be answering the first 4 questions on the bottom of page 69 with this
exercise.

Instead of just answering the 4 questions, we are going to turn this into an exercise
in using the data modeling tool, as well as creating the tables in our own database
schema.

Just as I also provided for the last assignment, I will also include the steps to create
the tables in some screenshots below. I will not be creating the Customer, Employee
or OrdrTbl in my examples, but I will create 3 tables that relate to one another.

We will get started by opening up SQL Developer Data Modeler. Once you have the
application open, you will look in the tree on the left side. You are going to notice
that under Designs [1] you will see Untitled_1


Since this is a new file, we are going to start by saving the document first. You will
fo to File Save as to save the file. I would like you to name it with your First Initial
+ Last Name followed by AssignmentTwo, as an example, my file will be
IBeckerAssignmentTwo This will make it easier for me to look over them all later.

Once you have done that, you will no longer see Untitled, and will see the name of
your file.



Once we have the file saved, we will begin by creating a new Relational Model. We
will do this by clicking on the Relational Models [1] folder to reveal the
Relational_1 model. Double click on that model and you will get a Model Properties
screen that will open. You are going to rename Relational_1 to Orders as well as
checking the Visible checkbox.


Then click on OK.

We will now have a blank page opened in our Data Model. The next step is to add
some tables. As you see from the diagram at the beginning of this assignment, we
will be creating 3 tables. As you follow along in this tutorial, you will be using the
names in the diagram. I will be using Table1, Table2 and Table3.


To create your first table you will look in the icon bar at the top. As you hover over
them, you will notice that one says Create Table (it is the second one in the picture
below:)


When you click on that icon, you will then draw a box (by left clicking and dragging
the mouse on the screen) on the blank page. Once you do that, you will get a new
window that says Table Properties


As you might have guessed, the first thing you are going to do is rename the table
from TABLE_1 to Customer

Once we create the table, we are going to need to add some columns to the table.
We do that by clicking Columns located on the left hand side of the window.

You will then click on the Green Plus sign to add new columns to the table as shown
in the image below:


In my example, I am adding a column called Column1 that is an Integer. I selected
Logical for the Datatype and then Integer from the Type drop-down. This column
is also my Primary Key, so I checked the PK box.


After adding a few columns to my table, it looks like this:


I will also go ahead and create 2 more tables that are similar.



I have created Table1 and Table2 that have Primary keys as well as Table3 which
while it has a primary key, it also will have 2 foreign keys. Remember, foreign keys
relate to the primary keys in the table they come from. This naming convention that
I am using is horrible, but it will at least serve the purpose of this tutorial without
giving you the answers to the homework.

The next step is to tell the data modeler that my Table1Column1 as well as
Table2Column1 are foreign keys. We do that with the icon that looks like this:
and it will be the 6
th
icon on the toolbar.
When you click on this button, you will define your foreign key by first clicking on
the table with the primary key that you want and dragging to the table you want to
define the foreign key on.

When you do that, you will get a new pop-up that looks like this:




We will have to click on the Associated Columns link on the left of the pop-up so
we can tell the tool that we are going to use the Table1Column1 column that we
already defined. Or else, it will create a new column for us.



When you have completed that, just click OK.

You will get the following message:

Just say Yes to that since we are not going to use the column that it created for us.

When that closes define your second relationship.

I now have the following:



You can right click on the screen and play with the layout if you wanted to,
sometimes it makes the model look cleaner.

Once you have it looking the way you want, please save your model again.

Now that you have finished modeling the three tables, we are going to take
advantage of the power of the modeling tool and have it generate the SQL for us to
create the three tables as well as the two foreign keys. To do this, we will click on
File Export DDL File

You will get the following pop-up:



SQL Developer Date Modeler has the ability to export to multiple different database
types. We are going to take the default of Oracle Database 11g since that is the
version we are using.

So click on Generate at the top. On the next screen, you are going to click Ok at the
bottom. You will now see the create statements. At the bottom of the screen you
are going to need to press Save to save the file, it will not include it in your data
model.

So as of now we have the following:
1) Data model for the 3 tables
2) SQL Script for the 3 tables

The next part of this assignment is to actually create those tables in your database
schema.

We are going to do that with the SQL Developer tool that you used to change you
password in last week.

To get started, open up SQL Developer and connect to the database. If you do not
have the connection information saved, it is as follows:

Connection name: anything you want
Username: FirstInitial+LastName ex IBecker
Password: your password

Hostname: dm.ecrl.marist.edu
Port: 1521
SID: MSIS537L711 or MSIS537L256 (depends on the section you are in, please use
the correct one)

Once you are connected, you will have a blank worksheet on the right. You will now
open the file that you had saved from the data modeler.

With the file open, your screen should look something like this:


You are going to run the script by pressing F5 and you will get a popup immediately
asking for the database connection you want to use:


Verify it is the correct one and press OK.

The script should run and in the section below your script, you should see the
following:

table TABLE1 created.
table TABLE1 altered.
table TABLE2 created.
table TABLE2 altered.
table TABLE3 created.
table TABLE3 altered.
table TABLE3 altered.
table TABLE3 altered.

Once that has completed, press F11 to commit your changes.

To verify that you tables exist, you can expand on the folders under your
connections like this:


You can also run the following database query:

select * from user_tables;

You will run that in the first tab that had opened:



Once you have verified that you have al of this completed, you are done with the
assignment.

Your deliverables are as follows:

Completed Data Model 25 pts.
Table creation script 5 pts.
Created tables in schema 25 pts.

Since the Data model and the SQL script are the only 2 files you have, you will
submit them with the assignment.