←Module 2
Lesson · 24 min

Creating Tables and Choosing Data Types

Build tables in Design view and choose data types that make invalid entries impossible rather than merely discouraged.

By the end of this lesson you can

  • Create a table in Design view and set a primary key
  • Choose the appropriate data type for each field
  • Set field properties including Required, Default Value, and Field Size
  • Explain why identifiers belong in text fields
📘 Reading Lesson

Lesson Notes

Read through the key concepts before you try the challenge.

Data types are your first line of defense

On the job

You build a supply inventory database at Lakeside Medical Associates.

You set every field to Short Text because it accepts anything. Six months later the quantity field contains '12', 'twelve', '12 boxes', and 'approx 12'. Nothing can be summed, sorted, or reported on, and the database cannot answer the one question it was built for.

Your task: Choose types that reject wrong data at the moment of entry.

A data type constrains what a field will accept. A Number field will not take 'twelve'. A Date/Time field will not take 'next Tuesday'. Choosing correctly at design time prevents a category of problem that is extremely tedious to repair afterwards.

TypeUse forNote
Short TextNames, addresses, codes, identifiersUp to 255 characters
Long TextNotes and commentsSortable but not efficiently indexed
NumberQuantities you will calculate withSet an appropriate Field Size
CurrencyMoneyAvoids the rounding errors of floating-point numbers
Date/TimeDates and timesEnables date arithmetic and correct sorting
Yes/NoTwo-state valuesStored as true/false
AutoNumberPrimary keysAccess assigns a unique value automatically
LookupA value chosen from a list or another tableEnforces consistent entry
AttachmentFiles linked to a recordGrows the file quickly; use sparingly
Access data types
Store an identifier you would never calculate with — a phone number, a ZIP code, a patient ID — as Short Text, not Number. A Number field strips leading zeros, so ZIP code 07030 becomes 7030. The test is simple: if you would never add two of these values together, it is text.
PropertyDoesUse it to
RequiredRefuses to save a record with this field emptyStop half-entered records
Default ValuePre-fills a valueReduce typing on fields that are usually the same
Field SizeCaps the length or numeric rangePrevent a 200-character state abbreviation
Validation RuleRejects entries failing a conditionRefuse a negative quantity
Validation TextThe message shown when the rule failsExplain what the user should do instead
Input MaskGuides entry into a fixed formatPhone numbers and dates
IndexedSpeeds searching and can enforce uniquenessFields you search or sort on constantly
Field properties worth setting
Worked example

Building the supply inventory table

Create a table recording items, quantities, costs, and reorder levels, designed so bad data cannot be entered.

  1. 1

    Create the table in Design view, not by typing into a datasheet.

    Design view makes you name each field and choose its type deliberately. Building by typing lets Access guess, and it guesses Short Text far too often — which is exactly how the scenario above happens.

  2. 2

    Add ItemID as AutoNumber and set it as the primary key.

    AutoNumber guarantees uniqueness with no effort and carries no meaning, which is what a key should be. Access will not enforce record uniqueness without a primary key.

  3. 3

    Set types by purpose: Quantity as Number, UnitCost as Currency, LastOrdered as Date/Time.

    Each type rejects data that does not belong. Currency specifically avoids the floating-point rounding that makes money columns fail to reconcile by a cent — a real problem with ordinary decimal fields.

  4. 4

    Add a Validation Rule of >=0 on Quantity, with Validation Text explaining it.

    A negative quantity on hand is meaningless. Catching it at entry is far cheaper than discovering it in a report, and the Validation Text is what makes the rejection useful rather than confusing.

  5. 5

    Set Required on ItemName and Quantity.

    Half-entered records are worse than no record, because they look complete in a list. Required makes the incomplete record impossible rather than merely discouraged.

Result: A table that refuses invalid entries at the point of entry rather than accumulating them.

Design the table deliberately and constrain it. Forms and reports are generated in seconds; a badly typed table takes months to repair.

Check your understanding

Which data type should be used for a five-digit ZIP code?

Challenge

Apply what you've learned in this lesson.

Build the table from your Module 1 design.

  1. Create a database named 'Lakeside Supplies'. Build a table in Design view with fields for item name, category, quantity on hand, unit cost, reorder level, and last ordered date. Choose a deliberate type for each and set an AutoNumber primary key.
  2. Set Required on item name and quantity, a Default Value on category, and a Validation Rule preventing negative quantities. Write Validation Text for it.
  3. Try to save a record with a blank item name and one with a quantity of -5. Record exactly what Access does in each case.
  4. Enter six valid records, then explain in two sentences which property you think prevents the most errors in practice.

Finished this lesson?

Progress is saved in this browser only. It is not a grade — official progress lives in Brightspace.