Table of Contents |
In a relational database, all the tables are related by one or more fields, so that it is possible to connect all the tables in the database through the field(s) they have in common. To connect tables in a relational database, one of the fields is identified as a primary key. A primary key is the unique identifier for each record in the table. A primary key must contain a unique value for each row of data. Additionally, a foreign key is a field in one table that links to the primary key in another table. To help you understand these terms further, let’s walk through the process of designing a database.
EXAMPLE
Suppose a university wants to create an information system to track participation in student clubs. After interviewing several people, the design team learns that the goal of implementing the system is to give better insight into how the university funds clubs. This will be accomplished by tracking how many members each club has and how active the clubs are. From this, the team decides that the system must keep track of the clubs, their members, and their events. Using this information, the design team determines that the following tables need to be created:When defining the fields in a database table, we must give each field a data type. A data type is a classification of the type of data that a field will hold. For example, the field Birth Year is a year, so it will be a number, while First Name will be text. Most modern databases allow for several different data types to be stored. There are two important reasons why we must properly define the data type of a field. First, a data type tells the database what functions can be performed with the data. For example, if we wish to perform mathematical functions with one of the fields, we must be sure to tell the database that the field is a number data type. So, if we have, say, a field storing birth year, we can subtract the number stored in that field from the current year to get age. The second important reason to define data type is so that the proper amount of storage space is allocated for our data. For example, if the First Name field is defined as a text (50) data type, this means 50 characters are allocated for each first name we want to store. However, even if the first name is only five characters long, 50 characters (bytes) will be allocated. While this may not seem like a big deal, if our table ends up holding 50,000 names, we are allocating 50 * 50,000 = 2,500,000 bytes for storage of these values. It may be prudent to reduce the size of the field so we do not waste storage space.
Some common data types and examples are listed here:
Data Type | Description | Example |
---|---|---|
Text | Used to store non-numeric data that is brief, generally under 256 characters. The database designer can identify the maximum length of the text. | “Hello world” |
Number | Used to store numbers. There are usually a few different number types that can be selected, depending on how large the largest number will be. |
1 -4 7.3 |
Yes/No | A special form of the number data type that is (usually) one byte long, with a 0 for “No” or “False” and a 1 for “Yes” or “True.” |
0 for “No” or “False” 1 for “Yes” or “True” |
Date/Time | A special form of the number data type that can be interpreted as a number or a time. |
9-6-17 10:04 AM |
Currency | A special form of the number data type that formats all values with a currency indicator and two decimal places. |
$45.00 £38.82 |
Paragraph Text | Used to store text longer than 256 characters. | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. |
Object | Used to store data that cannot be entered via keyboard, such as an image or a music file. |
Music file Image file |
Source: Derived from Chapter 4 of “Information Systems for Business and Beyond” by David T. Bourgeois. Some sections removed for brevity. https://www.saylor.org/site/textbooks/Information%20Systems%20for%20Business%20and%20Beyond/Textbook.html