Monday, April 22, 2013

Line 20: Chapter 7

Today we will be blogging about more exercises from our book, Chapter 7 this time, which has to do with criteria for a normal database. To this end we will be identifying problems in the RMH Homebase database.

7.1: This problem asks you to identify tables in the RMH Homebase database that violate the the following criteria for a normal database.

Criterion 5: Every entry in the table has exactly one value of the appropriate type.
Criterion 6: No attribute in the table is redundant with the primary key.

dbSchedules violates both of these criteria by itself. It allows more than one person to be entered into the persons column, which is a violation because you can have more than one value in this field.

It also violates Criterion 6, because it's primary key is just a combination of the phone number and the person's first name. This creates a primary key that automatically produces redundancies with the other attributes, as it is just a combination of them.

7.2 This question asks you to develop a few new php functions: get_shift_month, get_shift_day, get_shift_year, get_shift_start, and get_shift_end for the dbShifts.php module.

 This one is pretty easy, as all of these are basically tokenizing a string using the substring "-" as the breaking point. Normally you would have to write something to handle breaking it into substrings, and then adding them to a data structure to be references later, but php has a command that does this easily. Using the explode() function, you can break a string into tokens based on a key character. You just provide an array for the new tokens to go into. Since it is so easy, you can basically just change the index of the array you create for each of these functions. Here is an example of the month version of this get, using explode.

Function get_shift_month($id){
        $tokens = explode("-", $id);
        return $tokens[0];

}

You can basically just reuse this code for each function, just changing the index of the array to match the data you are trying to get.

7.3

No comments:

Post a Comment