Database Tutorial

Course Tutorial Site

Site Admin

Lab #2 : MySQL Tables

with 36 comments

Lab #2: MySQL Assignment

You begin these steps by running the cleanup_mysql.sql and create_mysql_store.sql scripts. A great starting point for this lab is to review the create_mysql_store.sql script. The create_mysql_store.sql script creates 10 tables. Your Lab #2 script creates 10 tables with some changes and alterations. You should use the script provided in the downloaded instance or create a script like:

-- Run the prior lab script.
\. /home/student/Data/cit225/mysql/lib/cleanup_mysql.sql
\. /home/student/Data/cit225/mysql/lib/create_mysql_store_ri.sql
 
TEE apply_mysql_lab2.txt
 
... insert code here ...
 
NOTEE

You should embed the verification queries inside your apply_mysql_lab2.sql script.

  1. [0 points] Tutorial on creating the SYSTEM_USER_LAB table and the SYSTEM_USER_LAB_S1 sequence, which is Step #1. The reasons for making the changes are:

    • Table, sequence, and constraint names are unique inside a schema or database.
    • All the tables, sequences, and constraints names must have counterparts that use an _LAB suffix or an _LAB_ between the base table constraint name and its number.

After making these changes for one table, the SYSTEM_USER_LAB table, you repeat the process by copying segments and editing them until you replicate the entire create_mysql_store_ri.sql script for tables with the _LAB suffix or an _LAB_ element between the base table constraint name and its number.

  1. [2 points] Create the SYSTEM_USER_LAB table described by the following description. The table should also have an auto-incrementing sequence on the SYSTEM_USER_ID column. The table should have an auto incrementing sequence that should start with a value of 1001:
  1. [2 points] Create the COMMON_LOOKUP_LAB table described by the following. It should have an auto incrementing sequence with a starting value of 1001:
  1. [2 points] Create the MEMBER_LAB table described by the following. It should have an auto incrementing sequence with a starting value of 1001:

  1. [2 points] Create the CONTACT_LAB table described by the following. It should have an auto incrementing sequence with a starting value of 1001:

  1. [2 points] Create the ADDRESS_LAB table described by the following. It should have an auto incrementing sequence with a starting value of 1001:

  1. [2 points] Create the STREET_ADDRESS_LAB table described by the following. It should have an auto incrementing sequence with a starting value of 1001:

  1. [2 points] Create the TELEPHONE_LAB table described by the following. It should have an auto incrementing sequence with a starting value of 1001:
  1. [2 points] Create the RENTAL_LAB table described by the following. It should have an auto incrementing sequence with a starting value of 1001:
  1. [2 points] Create the ITEM_LAB table described by the following. It should have an auto incrementing sequence with a starting value of 1001:

  1. [2 points] Create the RENTAL_ITEM_LAB table described by the following. It should have an auto incrementing sequence with a starting value of 1001:

  1. [0 points] You can confirm the creation of the ten tables with the following query:

Written by michaelmclaughlin

November 21st, 2014 at 1:01 am

Posted in

36 Responses to 'Lab #2 : MySQL Tables'

Subscribe to comments with RSS or TrackBack to 'Lab #2 : MySQL Tables'.

  1. Make sure to fix the path to the cleanup and create_store scripts.

    Jeremy

    14 Jan 15 at 2:00 pm

  2. In Step 1 you have us create the table system_user_lab with the field SYSTEM_USER_TYPE as NOT NULL. But when you have us insert the row into the table you do not specifiy a value. Should we put in a 1?

    Tyler

    15 Jan 15 at 8:10 pm

  3. When we are asked to add the constraints to the system_user_lab table for the system_user_group_id and the system_user_type, the instructions ask us to reference the system_user_lab table and the system_user_id column, but the validation says it references the common_lookup_lab table.

    mar09013

    15 Jan 15 at 10:41 pm

  4. Can you qualify which validation script is wrong by pasting it into a comment.

    michaelmclaughlin

    16 Jan 15 at 2:41 am

  5. Jeremy, It’s fixed. Thanks.

    michaelmclaughlin

    16 Jan 15 at 2:52 am

  6. Tyler, That’s true. It’s fixed and note that you’ll need to update that row after inserting values into the COMMON_LOOKUP_LAB table.

    michaelmclaughlin

    16 Jan 15 at 3:00 am

  7. MYSQL step 1

    Last name column in the first table shows that the character length is '1' but in a later table it shows as '20' which is correct?

    Joseph Tracy

    16 Jan 15 at 12:21 pm

  8. Step 4

    Currently

    'last name'
    'first name'
    'middle name'

    The other tables have been

    'first name'
    'middle name'
    'last name'

    Joseph Tracy

    16 Jan 15 at 3:52 pm

  9. Under all of the sections the check output needs to have “_lab” added to them under the primary key and foreign key columns.

    Tyler Nelson

    16 Jan 15 at 5:06 pm

  10. Bro. Mclaughlin, when you state the column names in step 6’s table, you have LINE_NUMBER NOT NULL Integer Maximum, when it is not actually in the rest of the lab.

    Tad Livingston

    17 Jan 15 at 10:56 am

  11. In step #1, it instructs us to create a unique index called SYSTEM_USER_LAB_U1. After creating it, the instructions read, “You can then use this query to display the unique constants on the table:” The example table does not show the unique index; however, when I run my program, the unique index is display. Is this a mistake on the lab’s part or mine?

    Carissa L

    17 Jan 15 at 11:58 am

  12. Carissa, You were right, the query was incorrect and the displayed output was wrong. I’ve updated both.

    michaelmclaughlin

    21 Jan 15 at 12:52 am

  13. Tad, You’re right the web page was wrong and the column was removed from the list of the STREET_ADDRESS_LAB table.

    michaelmclaughlin

    21 Jan 15 at 12:57 am

  14. Joseph, You’re right. It’s a typo and now it’s fixed.

    michaelmclaughlin

    21 Jan 15 at 1:06 am

  15. Joseph, It’s a great catch, and it’s now fixed.

    michaelmclaughlin

    21 Jan 15 at 1:10 am

  16. Tyler, Great catch. It’s fixed now.

    michaelmclaughlin

    21 Jan 15 at 2:04 am

  17. Step 2 states:

    You should then create a COMMON_LOOKUP_LAB_U1 unique index on the COMMON_LOOKUP table, and a COMMON_LOOKUP_LAB_N1 non-unique index on the COMMON_LOOKUP table:

    However, no columns are given for the N1 index, and the expected results do not show the N1 index. The instructions either need to remove the reference to the N1 index, or specify which column(s) should be in the index.

    Dave Stevenson

    23 Jan 15 at 6:17 pm

  18. In step 4, after creating non unique indexes CONTACT_N1 and CONTACT_N2, the verification code is expected to query the non-unique indexes. Instead the wrong verification code is present; it shows the foreign key constraints instead.

    Dave Stevenson

    23 Jan 15 at 6:36 pm

  19. I believe the constraint names in step 6:

    +--------------------+--------------------+-----------------+
    | table_name         | constraint_name    | constraint_type |
    +--------------------+--------------------+-----------------+
    | street_address_lab | PRIMARY            | PRIMARY KEY     |
    | street_address_lab | street_address_fk1 | FOREIGN KEY     |
    | street_address_lab | street_address_fk2 | FOREIGN KEY     |
    | street_address_lab | street_address_fk3 | FOREIGN KEY     |
    +--------------------+--------------------+-----------------+

    should have ‘_lab‘ in them:

    +--------------------+------------------------+-----------------+
    | table_name         | constraint_name        | constraint_type |
    +--------------------+------------------------+-----------------+
    | street_address_lab | PRIMARY                | PRIMARY KEY     |
    | street_address_lab | street_address_lab_fk1 | FOREIGN KEY     |
    | street_address_lab | street_address_lab_fk2 | FOREIGN KEY     |
    | street_address_lab | street_address_lab_fk3 | FOREIGN KEY     |
    +--------------------+------------------------+-----------------+

    Dave Stevenson

    23 Jan 15 at 6:57 pm

  20. In step 7, the instructions state the telephone_lab_n1 index consists of two columns, but the verification code expected results show only one of them.

    Dave Stevenson

    23 Jan 15 at 7:11 pm

  21. Dave, Great catch! You’re right, and I’ve updated the page with the correction.

    michaelmclaughlin

    26 Jan 15 at 2:41 am

  22. step 4. reference for the FK for member_lab_id is incorrect.

    Joseph Tracy

    31 Jan 15 at 12:30 pm

  23. step 9.

    address_lab_id is included in lab 2 item_lab but is not included in lab 4 item_lab and throws an error for missing input.

    Joseph Tracy

    31 Jan 15 at 1:59 pm

  24. On step 2, creating the common_lookup_lab unique and non unique indexes, you don’t tell them in the instructions which columns to add the indexes on. Also, in the validation query, you don’t have anything for the non-unique index.

    Jeremy

    2 Feb 15 at 12:14 pm

  25. The first paragraph has many instance of ‘oracle’ instead of mysql
    “You begin these steps by running the cleanup_oracle.sql and create_oracle_store.sql scripts. A great starting point for this lab is to review the create_oracle_store.sql script. The create_oracle_store.sql script creates 10 tables. Your Lab #2 script creates 10 tables with some changes and alterations. You should use the script provided in the downloaded instance or create a script like”

    Brett

    20 Feb 15 at 3:45 pm

  26. Your script is running ri, and later labs say to run ri2. I think there needs to be some consistency in what ri to run. as well, the instructions need to match consistently to which ri you are using. Example lab 7’s verification and all instruction from lab 5 on is based on ri2. However in this lab they do not learn about the rating_agency table which would benefit them as they have no idea of its existence until lab 6 when they need to insert into item. and find out they cannot insert into item with strings for rating.

    Brett

    20 Feb 15 at 3:55 pm

  27. Joseph, I believe that the address_lab_id is fixed.

    michaelmclaughlin

    8 Mar 15 at 2:52 am

  28. Joseph, That MEMBER_LAB_ID reference is fixed. Thanks.

    michaelmclaughlin

    8 Mar 15 at 2:58 am

  29. Brett, The Oracle references have been replaced with MySQL references. Thanks!

    michaelmclaughlin

    8 Mar 15 at 3:01 am

  30. Brett,

    The lab design has two purposes and yes using the _ri and _ri2 scripts are a critical components for accomplishing certain goals:

    • First, they ensure that the scripts the students develop are incompatible with labs five forward, that’s why they use the create_mysql_store_ri.sql script during this lab and the create_mysql_store_ri2.sql script.
    • Second, they present differences that compel re-writes of the lab and inability to reuse any of the INSERT statements (and yes, there are architectural details later that introduce additional primary and foreign key concepts).

    You’re correct, the INSERT statements from Lab #4 aren’t reusable because of the differences but there are examples in the seed_mysql_store_ri2.sql script that the student can leverage in Lab #6.

    michaelmclaughlin

    8 Mar 15 at 12:21 pm

  31. Jeremy, Great catch! I’ve fixed it. Thanks!

    michaelmclaughlin

    8 Mar 15 at 11:37 pm

  32. Dave, The diagnostic program was changed earlier along with the output for Step #7. If you notice that any further change is required, please post another comment.

    michaelmclaughlin

    9 Mar 15 at 12:18 am

  33. Dave, Below the validation of foreign key constraints, you’ll find the validation script for CONTACT_N1 and CONTACT_N2 non-unique constraints. Post another comment if you still see a problem.

    michaelmclaughlin

    9 Mar 15 at 12:24 am

  34. Dave, Great catch! I’ve added the material for the COMMON_LOOKUP_LAB_N1 index.

    michaelmclaughlin

    9 Mar 15 at 12:46 am

  35. In step one on instruction L the oracle instructions are presented instead of the mySQL instructions.

    Copy the content from line 27 to 79 from the create_oracle_store.sql script and paste it to lines 23 through 75. Then, make the following changes:

    Jason

    23 Sep 15 at 1:17 pm

  36. Jason, I’ve replaced it with the following:

    Copy the content from line 11 to 55 from the create_mysql_store.sql script and paste it to lines 32 through 76.

    michaelmclaughlin

    24 Sep 15 at 11:46 pm

Leave a Reply