2-msis537l assignment two (1)

Upload: aakash-bhatia

Post on 02-Jun-2018

222 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/11/2019 2-MSIS537L Assignment Two (1)

    1/12

    Assignment TwoChapter 3 Create table statements55 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.

  • 8/11/2019 2-MSIS537L Assignment Two (1)

    2/12

    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 noticethat 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 FileSave 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

    IBeckerAssignmentTwoThis 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.

  • 8/11/2019 2-MSIS537L Assignment Two (1)

    3/12

    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_1model. Double click on that model and you will get a Model Properties

    screen that will open. You are going to rename Relational_1to Ordersas well as

    checking the Visiblecheckbox.

    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 thenames in the diagram. I will be using Table1, Table2 and Table3.

  • 8/11/2019 2-MSIS537L Assignment Two (1)

    4/12

    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_1to Customer

    Once we create the table, we are going to need to add some columns to the table.

    We do that by clicking Columnslocated 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 shownin the image below:

  • 8/11/2019 2-MSIS537L Assignment Two (1)

    5/12

    In my example, I am adding a column called Column1 that is an Integer. I selected

    Logicalfor the Datatypeand then Integerfrom the Typedrop-down. This column

    is also my Primary Key, so I checked the PKbox.

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

  • 8/11/2019 2-MSIS537L Assignment Two (1)

    6/12

    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

    Table2Column1are foreign keys. We do that with the icon that looks like this:

    and it will be the 6thicon 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:

  • 8/11/2019 2-MSIS537L Assignment Two (1)

    7/12

    We will have to click on theAssociated Columnslink 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:

  • 8/11/2019 2-MSIS537L Assignment Two (1)

    8/12

    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 onFileExportDDL File

    You will get the following pop-up:

  • 8/11/2019 2-MSIS537L Assignment Two (1)

    9/12

    SQL Developer Date Modeler has the ability to export to multiple different database

    types. We are going to take the default of Oracle Database 11gsince that is the

    version we are using.

    So click on Generateat the top. On the next screen, you are going to click Okat 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 databaseschema.

    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:

  • 8/11/2019 2-MSIS537L Assignment Two (1)

    10/12

    Connection name: anything you want

    Username: FirstInitial+LastName ex IBecker

    Password: your password

    Hostname: dm.ecrl.marist.eduPort: 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 F5and you will get a popup immediately

    asking for the database connection you want to use:

  • 8/11/2019 2-MSIS537L Assignment Two (1)

    11/12

    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 F11to 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:

  • 8/11/2019 2-MSIS537L Assignment Two (1)

    12/12

    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.