In-Depth Guide – Database Basics Creating and Populating Learning Objectives By reading and completing the activities in this chapter, you will be able to: Given a database logical schema, create a database in Microsoft Access, including o Creating tables, fields and primary key o Establishing relationships between tables Add records to a table Chapter Outline Introduction Creating a database Creating tables Creating relationships Populating tables with data Summary Introduction In this chapter, we will help you learn how to create and populate a database using Microsoft Access. While most of you will probably never create large databases as a major part of your jobs, it is useful to know how to create small databases. As discussed in Chapter 5, using a database management system (such as Access) to store some types of data can be very useful. As a result, being able to create simple databases may be a handy skill in the future. Fortunately, personal-level database management systems, such as Access, make it relatively easy to create a database. Once you have a good database design, there are a few key things you need to be able to do when creating a database. You need to be able to: Create tables Create fields within tables Choose the proper data type for each field (for example, text, numeric or date/time) Establish relationships between tables Once the database is created, you will also need to know how to add records to the tables that make up the database. We will use the “Wish-List” database from Chapter 5 to illustrate how to accomplish all of these tasks. The schema (design) of the database is shown in Figure 1.
15
Embed
In-Depth Guide Database Basics Creating and Populating · In-Depth Guide – Database Basics Creating and Populating Learning Objectives By reading and completing the activities in
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
In-Depth Guide – Database Basics Creating and Populating
Learning Objectives By reading and completing the activities in this chapter, you will be able to:
Given a database logical schema, create a database in Microsoft Access, including
o Creating tables, fields and primary key
o Establishing relationships between tables
Add records to a table
Chapter Outline Introduction
Creating a database
Creating tables
Creating relationships
Populating tables with data
Summary
Introduction In this chapter, we will help you learn how to create and populate a database using Microsoft
Access. While most of you will probably never create large databases as a major part of your
jobs, it is useful to know how to create small databases. As discussed in Chapter 5, using a
database management system (such as Access) to store some types of data can be very useful. As
a result, being able to create simple databases may be a handy skill in the future. Fortunately,
personal-level database management systems, such as Access, make it relatively easy to create a
database.
Once you have a good database design, there are a few key things you need to be able to do
when creating a database. You need to be able to:
Create tables
Create fields within tables
Choose the proper data type for each field (for example, text, numeric or date/time)
Establish relationships between tables
Once the database is created, you will also need to know how to add records to the tables that
make up the database.
We will use the “Wish-List” database from Chapter 5 to illustrate how to accomplish all of these
tasks. The schema (design) of the database is shown in Figure 1.
Figure 1 - Wish-List Database Schema
Creating a Database in Access
In this section, we give you step-by-step instructions for creating and populating the Wish-List
database. The first step (once you have a good design) is to give the database a name. This
effectively creates an empty container for the database. Access stores all database elements,
including the data in a single file on your computer. In Access 2007, this file as an .accdb file
extension.
To create the database file, simply start Access then click on “Blank Database” in the Access
Getting Started screen, as shown in Figure 2.
Figure 2 - Access Getting Started Screen One of the most important aspects of creating a new, blank Access database is knowing where it
will be stored. You should make it a habit to click on the folder icon in the lower right-hand
corner of the opening Access screen. This allows you to specify the location in which the
database file will be stored. Also be sure to give the database a meaningful name. These steps
will help you locate the database in the future. The relevant opening Access screen is shown in
Figure 3. Once you have created the database file, you can start creating tables.
Figure 3 - Specifying the Database Name
and Location
Creating Tables
Creating tables in Access is not difficult if you have a good data model. To create a table, select
the Create ribbon, then Design View, as shown in Figure 4. Typically with a new database,
Access takes you directly to the Table Tools ribbon, from which you can simply choose the
Design View. When you do so, Access brings up the Save As dialog box, which allows you to
specify the name for your table.
Figure 4 - Creating a Table
Selecting the Design View takes you to a form for adding the fields that make up your table, as
shown in Figure 5. Enter the name of the field in the “Field Name” column of the form. While
Access allows spaces in field names, it is generally a bad idea to do so. So, we recommend
avoiding spaces. When a field name is made up of more than one word, capitalizing the first
letter in each word (as in FirstName) makes the field name easier to read.
Figure 5 - Entering Table Information
In addition to the Field Name for each field, you will also need to select the data type, which
specifies what sort of data can be stored in each field. Access’ data types are listed and briefly
described in Table 1. Data types generally have additional properties that can be set. Discussing
these in detail is beyond our scope. However, there is one property we want to mention. For text
fields, you should set a reasonable field size rather than the default of 255 characters, which is
the maximum. For example, you probably do not need 255 characters for the FirstName field.
See http://office.microsoft.com/en-us/access-help/introduction-to-data-types-and-field-
properties-HA010233292.aspx#BM2b for more information about field properties.
Data Type Description Text Relatively short (up to 255 characters) alphanumeric values. Memo Long blocks of text. Allows more than 255 characters. Number Numeric values. There are several different variations of the
number data type, including integer (from -32,768 to 32,767), long integer, dingle and double precision.
Date/Time Time-based data, including dates and times. The data can be displayed in several different formats.
Currency Monetary values. Autonumber A number that is automatically generated for each record in a
table. The numbers are stored as integer values. The only purpose of an autonumber field is to make a record unique.
Yes/No Boolean values such as true/false, yes/no and on/off. OLE Object External objects that conform to the OLE standard. Microsoft
recommends using the Attachment data type, which is less restrictive than OLE Object.
Hyperlink Links to email addresses, websites, etc.
Attachment Files such as images and audio. You can attach multiple files to a single record.