Database Components  «Prev  Next»

Lesson 5 How data is stored
Objective Describe how an Access database stores data in a table.

How Data is stored in Access Database

In a Microsoft Access database, data is organized and stored in structures known as tables, which are the fundamental building blocks for storing and managing data within the database. Each table is designed to hold data about a specific subject, such as employees, products, or orders, and is composed of rows and columns, similar to a spreadsheet. A table in an Access database is structured as follows:
  1. Rows (Records): Each row in a table represents a single record, which is an individual entry or instance of the data type the table is designed to store. For example, in a table designed to store information about employees, each row would represent a single employee.
  2. Columns (Fields): Each column in a table represents a field, which is a specific piece of information that the database stores about each record. Continuing with the employee table example, the columns might include fields such as Employee ID, Name, Position, Department, and Hire Date. Each field is assigned a specific data type, such as text, number, date/time, or currency, which defines the nature of the data it can hold and how it can be manipulated.
  3. Primary Key: A primary key is a field (or combination of fields) that uniquely identifies each record within a table. No two records can have the same value in the primary key field(s), ensuring data integrity and enabling efficient data retrieval. For instance, an Employee ID field might serve as the primary key in an employee table because each employee ID is unique.
  4. Data Types: Access databases support various data types for fields, such as Text, Memo (Long Text), Number, Date/Time, Currency, AutoNumber (for automatically generating unique values), Yes/No (Boolean), OLE Objects (for storing files such as images or documents), Hyperlink, and Attachment. The choice of data type for each field is critical as it determines what kind of data the field can store and how much space it will use.
  5. Indexes: Indexes can be created on fields to speed up the retrieval of records. An index creates an internal structure that the database engine can use to quickly locate data. While a primary key is automatically indexed, additional indexes can be added to fields frequently used in search criteria or in joining tables in queries.
  6. Relationships: Tables within an Access database can be related to each other with relationships. These relationships define how data in one table is associated with data in another, enabling the creation of complex queries and ensuring data integrity through referential integrity rules. For example, an Orders table might have a relationship with a Customers table, linking each order to the customer who placed it.
  7. Validation Rules and Default Values: Fields in Access tables can have validation rules to enforce data integrity by restricting the type of data that can be entered into a field. Default values can also be specified for fields to automatically populate them with a predefined value when a new record is created.

By carefully designing tables with appropriate fields, data types, and relationships, a Microsoft Access database can efficiently store, organize, and manage data, providing a robust platform for data analysis, reporting, and decision-making.
In an Access database raw data is stored in tables. Tables are the most basic of the Access database objects and every Access database must have at least one, otherwise you would have no data to work with. Tables are structured with rows and columns, where the rows are called records and the columns are called fields. Here is an example:
Data stored in a table
Data stored in Access table

Table Field

A field is a category of information. The table shown above has separate fields for first name, last name, address, city, state, and zip code information. Each record (alson known as row) is a collection of fields, that is, one piece of data for each field. A record holds related data for one entity. In the table shown, each record holds the contact information for one person. Unlike a spreadsheet, the rows and columns in a database table cannot be reversed
  1. columns are always fields, which contain a category of data, and
  2. rows are always records, which contain a number of pieces of related data.

It is important to break your data into small, but meaningful, pieces.

Breaking Data into Fields

You may have noticed that I have broken down name and address pieces into small parts. For instance, I do not have one field for name information; I have two: one for first name and one for last. And I do not have one address field; I have three:
  1. one for the street address,
  2. one for the city, and
  3. one for the state.
Breaking up the data this way gives me more flexibility when I need to analyze or use the data. For instance, if I had only one field for the full name, I wouldn not be able to sort by last name, or address a letter to Ms. Young, using just the last name. If I had only one field for address I would not be able to sort the data by state or zip code. When data is broken into small pieces it gives the database more flexibility for sorting and analysis. My work involves financial and statistical number crunching. The business data is stored in Access, but I use many of the functions available in Excel to get my work done. Is there a way to use the Excel functions directly from Access, rather than copying and pasting my data from Access into Excel? Thanks to the availability of an object model paradigm for coding, it is relatively easy to hook into Excel and make use of Excel functions from within Access.

Passing Parameters to SQL Server

Most of my data is stored in a SQL Server database. The DBA only allows me to access the database by using a stored procedure, but the stored procedures require parameters. How can I pass parameters to SQL Server to get the data I want?

Let us assume that the following stored procedure exists on the SQL Server database. The stored procedure takes two parameters,
  1. @StartDate and
  2. @StopDate,
both of which have a type of datetime:
Select *
From DowJones
Where [Date] Between @StartDate And @StopDate

To call this procedure from an Access VBA script, you can use an ADO Command object to populate a Recordset object, like this:
Dim rs As ADODB.Recordset
Dim cmd As ADODB.Command
Set cmd = New ADODB.Command
cmd.ActiveConnection = "provider=sqloledb;Data Source=Athena;" & _
cmd.CommandText = "GetData"
cmd.CommandType = adCmdStoredProc
cmd.Parameters("@StartDate").Value = CDate("1/1/2015")
cmd.Parameters("@StopDate").Value = CDate("1/1/2016")
Set rs = cmd.Execute

After creating a new instance of the Command object, you need to specify how to connect to your database. This value is known as a connection string, and it can be assigned to the ActiveConnection property of the Command object. Next, specify the name of the stored procedure in CommandText, and indicate that this value refers to a stored procedure, not a table or a SQL statement.

ADO Parameters

The Refresh method instructs ADO to connect to the database to get the definitions of all the parameters. The results are saved in the Parameters collection. Finally, you can specify the value for each parameter, and use the Execute method to create a new Recordset object populated with the results of the stored procedure.

  1. queries,
  2. forms, and
  3. reports.

Access Database Analogy

An Access database is nothing more than an automated version of the filing and retrieval functions of a paper filing system. Access databases store information in a carefully defined structure. Access tables store a variety of different kinds of data, from
  1. simple lines of text (such as name and address) to
  2. complex data (such as pictures, sounds, or video images).
Storing data in a precise format enables a database management system (DBMS) like Access to turn data into useful information.
Tables serve as the primary data repository in an Access database. Queries, forms, and reports provide access to the data, enabling a user to add or extract data and presenting the data in useful ways. Most developers add macros or Visual Basic for Applications (VBA) code to forms and reports to make their Access applications easier to use.

Access RDBMS

A relational database management system (RDBMS), such as Access, stores data in related tables. For example, a table containing employee data (names and addresses) may be related to a table containing payroll information (pay date, pay amount, and check number). Queries allow the user to ask complex questions such as:
"What is the sum of all paychecks issued to Byron Janis in 2021?"

from these related tables, with the answers displayed as onscreen forms and printed reports. One of the fundamental differences between a relational database and a manual filing system is that, in a relational database system, data for a single person or item may be stored in separate tables. For example, in a patient management system, the patient's name, address, and other contact information is likely to be stored in a different table from the table holding patient treatments. In fact, the treatment table holds all treatment information for all patients, and a patient identifier (usually a number) is used to look up an individual patient’s treatments in the treatment table.
In Access, a database is the overall container for the data and associated objects. It is more than the collection of tables, however a database includes many types of objects, including queries, forms, reports, macros, and code modules. As you open an Access database, the objects (tables, queries, and so on) in the database are presented for you to work with. You may open several copies of Access at the same time and simultaneously work with more than one database, if needed.

SEMrush Software