CS377: Database Design - Data Organization: Fields, Records, and Keys

Activity Goals

The goals of this activity are:
  1. To define a record, field, and key in a database system
  2. To explain the importance and challenges of internal consistency

The Activity

Directions

Consider the activity models and answer the questions provided. First reflect on these questions on your own briefly, before discussing and comparing your thoughts with your group. Appoint one member of your group to discuss your findings with the class, and the rest of the group should help that member prepare their response. Answer each question individually from the activity, and compare with your group to prepare for our whole-class discussion. After class, think about the questions in the reflective prompt and respond to those individually in your notebook. Report out on areas of disagreement or items for which you and your group identified alternative approaches. Write down and report out questions you encountered along the way for group discussion.

Model 1: Records, Fields, and Keys

Ham Radio Logbook Showing Two Records with Slightly Different Field Values

Questions

  1. What records do you see in the data? What fields?
  2. What should happen if a particular field does not have a value?
  3. Two records are sometimes linked together; what do you think this means in this application?
  4. The two records are somewhat different; how, and what should be done about this?
  5. What field(s) are most likely to be unique throughout the table? These are referred to as a key, but a single serial number is often used instead to guarantee uniqueness.

Model 2: Internal Consistency

An Example Gradebook

Questions

  1. Which fields should a user be able to update? Which ones should a user not update directly, and why?

In the field of databases and data management, it is essential to understand how data is organized to effectively store, retrieve, and manipulate information. One fundamental concept is the organization of data into fields, records, and keys, which forms the foundation of many database systems. In this context, a field represents an individual data item, a record represents a set of related fields, and a key serves as a unique identifier for each record.

Fields

A field is a single piece of information stored in a database. It represents an attribute of an entity or an object. For instance, in a database of employees, fields could include the employee’s name, age, and job title. Each field contains a specific type of data, such as text, number, date, or Boolean.

A field, also known as an attribute, is the smallest unit of data in a database system. It can hold various types of data, such as numbers, text, dates, or even binary values. Fields should be carefully defined to ensure consistency and accuracy in data representation. For instance, when designing a database for a library, fields like book title, author, publication year, and ISBN number can be defined to store relevant information.

In Python, fields can be represented using variables of appropriate data types. For example, consider a field called age to store the age of individuals. We can define and assign a value to this field as follows:

age = 25

Records

Records are collections of related fields that represent a complete unit of information. In the context of a database, a record typically refers to a row in a table. For example, an employee record may include fields such as name, age, job title, department, and salary.

A record is a collection of related fields that together represent a complete set of information. Records allow us to organize data efficiently and facilitate data retrieval and manipulation operations. In the library database example, each book can be represented as a record, consisting of fields such as title, author, publication year, and ISBN number.

In Python, records can be represented using various data structures such as lists, tuples, or dictionaries. For instance, suppose we define a record representing a person’s information as a dictionary:

person = {
    "name": "John",
    "age": 25,
    "gender": "Male"
}

Here, the keys "name", "age", and "gender" represent the fields, and their corresponding values represent the data associated with each field.

Keys

A key is a field or combination of fields used to uniquely identify each record within a database table. Keys are crucial for efficient querying and indexing operations. A primary key is a unique identifier for a record and is often used as a reference for other tables. Alternatively, a composite key is a combination of two or more fields that, when combined, uniquely identify a record. There are various types of keys, such as primary keys, candidate keys, and foreign keys.

In Python, keys can be implemented using a combination of fields that form a tuple or a dictionary. For instance, let’s consider a record representing a book in a library database, where the ISBN number can serve as the key:

book = {
    "title": "Introduction to Database Systems",
    "author": "C. J. Date",
    "publication_year": 2004,
    "isbn": "978-0321197849"
}

Here, the "isbn" field serves as the key, which uniquely identifies this particular book record.

Python Examples

In Python, data can be organized using data structures such as dictionaries, lists, and classes. Here are some examples of organizing data using Python:

  1. Dictionary example:
    employee = {
        'name': 'John Doe',
        'age': 30,
        'job_title': 'Software Engineer',
        'department': 'IT',
        'salary': 50000
    }
    
  2. List of dictionaries example:
    employees = [
        {'name': 'John Doe', 'age': 30, 'job_title': 'Software Engineer', 'salary': 50000},
        {'name': 'Jane Smith', 'age': 25, 'job_title': 'Data Analyst', 'salary': 45000},
        {'name': 'Mike Johnson', 'age': 35, 'job_title': 'Project Manager', 'salary': 60000}
    ]
    
  3. Class example:
    class Employee:
        def __init__(self, name, age, job_title, salary):
            self.name = name
            self.age = age
            self.job_title = job_title
            self.salary = salary
       
    employee = Employee('John Doe', 30, 'Software Engineer', 50000)
    

Submission

I encourage you to submit your answers to the questions (and ask your own questions!) using the Class Activity Questions discussion board. You may also respond to questions or comments made by others, or ask follow-up questions there. Answer any reflective prompt questions in the Reflective Journal section of your OneNote Classroom personal section. You can find the link to the class notebook on the syllabus.