Home > Articles > Data > Access

Creating a Database Table

With the database created, the next step is to create one or more database tables, or just tables for short. The table is the object in the database that actually holds your information. Each table consists of one or more records, containing data stored in fields. Going back to our earlier file cabinet analogy, think of each record as a form in the file folder (one per person), and the fields as the data that someone filled in for that person—the fields are where the actual information is stored. We're creating a guest book table for our Web site that has seven fields: email address, name, comment, gender, age, an option to hide a user's email address from other users, and the date on which the comment was posted.

After you click the Create button to create your database (as described in the preceding section), Access displays what I call the "start window" (see Figure 3). From the start window you can create not only tables, but a number of other important database objects, such as queries, forms, and reports. These objects are listed under the Objects button on the left side of the start window.

Figure 3 The "start window."

To create the guest book table, follow these steps:

  1. First, if your screen doesn't look like Figure 3, click the word Tables (it doesn't look like a button, but it is) to display the following icons:

    • Create table in Design view

    • Create table by using wizard

    • Create table by entering data

  2. Double-click the icon labeled Create table in Design view.

This step opens the "table design window"—a window with the title Table 1: Table (see Figure 4).

Figure 4 Table design window sans toolbar menu.

Figure 4 doesn't have the Table Design toolbar displayed, and we'll need it. To display the toolbar, select View, Toolbars, Table Design, if it isn't already checked on your menu (see Figure 5). The Table Design toolbar appears below the menu (see Figure 6).

Figure 5 Selecting the Table Design toolbar for display.

Figure 6 Table design window with Table Design toolbar displayed.

The table design window contains three columns: Field Name, Data Type, and Description. Field Name is where you label the different pieces of information your table will hold. Data Type is the specific type of information (more on types later). Description is a comment about the information.

Recall that we're creating a guest book table to hold the following pieces of information: email address, name, comment, gender, age, an option to hide the email address, and date posted. Each piece of information is a field that we have to add to our database table. Let's start off with the most basic field—a text field.

Text Fields: Creating the email Field

In general, creating any field in a table is a three-step process:

  1. Enter the name of the field. A valid field name in Access is a combination of letters and numbers, with the important restriction that the first character has to be a letter. You can include spaces and other characters in the field name, but try to avoid them if possible—they often lead to subtle bugs that are hard to find. Finally, field names are not case-sensitive; Email, email, and even eMaIl refer to the same field as far as the database is concerned.

  2. Enter the field's data type. The data types include Text, Memo, Number, Date/Time, and Yes/No.

  3. Set the field's properties. The properties vary by data type; for example, for a Text field, important properties include Field Size, Default Value, and Allow Zero Length.

  4. (Optional) Enter a description for the field.

To create the email field, follow these steps:

  1. Type email in the first blank space under Field Name.

  2. After entering a field name, press Tab or click in the Data Type cell adjacent to the field name. (See Figure 7.)

    You're ready to set your field's data type. Notice the down-arrow button on the right side of the Data Type box. Clicking the button displays a drop-down list of the data types you can assign to the field (see Figure 8). If the information consists of a combination of letters and numbers and the total size of that combination is less than 255 characters, select Text as the data type. (We'll explain the other data types shortly.) All email messages in our sample database will be restricted to 255 characters, so the email field is a Text data type.

  3. Figure 7 Creating the email field.

    Figure 8 Data types.

  4. Click the Text item in the drop-down list.

  5. In general, you should add a comment to your field—sort of like commenting your code. For this field, we'll enter the description This is the user's e-mail address (see Figure 9). To speed our tutorial along, we'll omit comments for the rest of the fields.

  6. Figure 9 Setting a comment for the email field.

  7. The final step is to set your field's properties. The bottom section of the table design window lists a number of properties you can set, which vary according to your field's data type. The default text field size is 50 characters, which may be too small for some email addresses, so change it to 255 characters by typing 255 in the text box to the right of the Field Size label, and then pressing Enter (see Figure 10).

Figure 10 Setting a default value of 255 characters for the email field.

You're done setting the e-mail field! Next we'll add the comment field.

Memo Fields: Creating the comment Field

You might guess that the guest book's comment field would use the Text data type (a "text field") just like the email field, where we set the field size to the maximum of 255 characters. Honestly, for most user comments a text field would suffice. However, some users might enter comments longer than 255 characters. For textual information whose size is more than 255 characters, you need a Memo field, which can accept a maximum of approximately 64,000 characters.

Follow these steps to create the comment field:

  1. Type comment as the field name.

  2. Open the Data Type drop-down list and select Memo (see Figure 11).

That's it for the comment field!

Figure 11 Creating the comment field.

Most of the time you won't need to change any of the memo field's property values from their defaults. However, we should point out that it's common to set the Allow Zero Length property to Yes for those memo fields that are optional; for example, a "special shipping instructions" field in a customer order table. However, for our guest book we always want the user to type a comment, so we'll leave this property set to its default (No).

As you can probably guess, creating the other fields in the guest book table is not a difficult procedure. The key is to know when to use the various data types and what values you need for the field properties.

Number Fields: Creating the age Field

There are two ways to get a user's age. The first way is simply to ask the user for his or her age (in your HTML form) and the second is to get the user's birthdate and calculate the user's age relative to the current date. The first way is easier, so we'll do that, which requires that you create a field whose data type is Number. As the name implies, you use a Number field whenever you have numeric information, which includes both whole numbers (123, 1024, 7) and real numbers (6.023, 1.99, 3.14159265358979).

Note: If you're dealing with monetary information, use the Currency data type rather than the Number data type.

To create our guest book's age field as a Number data type, follow these steps:

  1. Type age as the field name.

  2. Open the Data Type drop-down list and select Number (see Figure 12).

Figure 12 Creating the age field.

Important Number field properties include Format and Decimal Places, both of which affect how the database displays numbers. Note that these properties only affect a number's display unless you change the Field Size property. However, most of the time you'll keep the default values for the Number field's properties.

Date/Time Fields: Creating the dateposted Field

It's common in Web site guest books to keep track of when a user "signed" the guest book. Whenever you have time-based information such as a date, a time, or a combination of both, you create a field whose data type is Date/Time. We'll create a Date/Time field named dateposted and set its default value so that when a user signs the guest book the current date and time are automatically inserted.

You create a Date/Time field almost the same way you create any other field:

  1. Type dateposted as the field name.

  2. Open the Data Type drop-down list and select Date/Time (see Figure 13).

  3. Figure 13 Creating the dateposted field.

    For our guest book, we really don't want the user to type the date he or she posted the message. For one thing, the user may type the wrong date. More importantly, however, you shouldn't have the user enter any information that the database can calculate automatically, such as the current date/time.

  4. Enter Now() as the Default Value in the Field Properties section of the table design window (see Figure 14).

Figure 14 Setting the default value for the dateposted field.

The database will now automatically substitute the current date and time into the dateposted field—there's no need to have a text box in your HTML guest book form that asks the user for the current date.

Yes/No Fields: Creating the hideEmail Field

There are cases when the information you get from the user can only have two values, such as yes/no or true/false. Whenever you have such Boolean values, you use the Yes/No data type.

In our guest book example, for security reasons we want to give our users the option of hiding their email addresses from other users viewing the guest book. To implement this option in our HTML guest book form, we would have a check box labeled Hide E-mail? If a user checks the box, we don't display his or her email address; otherwise, we do. Since this check box can only have two values—it's either checked or not—a Yes/No field is appropriate for recording the user's choice.

To create a Yes/No field to store the user's choice, follow these steps:

  1. Enter hideEmail as the field name.

  2. Open the Data Type drop-down list and select Yes/No (see Figure 15).

  3. Figure 15 Creating the hideEmail field.

  4. In most cases, you want to at least set a default value for the Yes/No field. In the Field Properties section of the table design window, enter Yes for the Default Value property (see Figure 16).

    You can also change the format of the Yes/No field so that instead of entering or displaying yes or no as values, you can instead enter or display True/False or On/Off. For our purposes, however, Yes/No is the proper format.

Figure 16 Setting the default value for the hideEmail field.

You're now ready to do some exercises on your own. In the following exercises you'll complete the guest book table by creating a name field and a gender field.

Exercise 1: Creating the name Field

In addition to the aforementioned fields, you also want to get the name of the user who is signing your guest book. To simplify matters, we'll use one field to hold the user's entire name—first, middle, and last names. Your task is to do the following:

  1. Create a field called name whose data type is Text.

  2. Set the field size for name to the maximum 255 characters.

  3. Make the name field optional by setting Allow Zero Length to Yes.

  4. Set the default value for this field to Declined to Specify.

If you did this exercise correctly, your table design window should look like Figure 17.

Figure 17 Adding the name field.

We'll do one more exercise, just for fun!

Exercise 2: Creating the gender Field

The final field we'll add to our guest book table is a field to hold the user's gender. Although gender typically takes only two values—male or female—and we could use a Yes/No field, we'll simply use a text field to store this information. Your task is to do the following:

  1. Create a field called gender whose data type is Text.

  2. Set the field size for gender to six characters, or just enough to hold the value female (which is six characters).

  3. Set the default value for this field to female. Unlike the name field, which is optional, let's make the user supply gender information. Don't set the value of Allow Zero Length to Yes in the Field Properties section.

If you did this exercise correctly, your table design window should look like Figure 18.

Figure 18 Adding the gender field.

You're almost done. The penultimate step is to set a primary key for your guest book table.

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020