Professional Documents
Culture Documents
All of the data in a table should refer to the same subject. For example, all of the data in the
Employees table should refer to employees, all of the data in the Students table should refer to
students, and all of the data in the Courses table should refer to courses.
You can view an Access database as a collection of related tables. For example, in a database
that contains tables for Employees, Students, and Courses, the Employees table lists the
employees, the Students table lists students, and the Courses table lists the courses students
can take.
After Access creates a blank database, it opens in Datasheet view and makes available the
tools you need to create a table. Datasheet view displays a table as a set of columns and rows.
When you view a blank database for the first time in Datasheet view, you see a column named
ID. This column is by default the primary key field.
A primary key is a field or combination of fields that uniquely identify each record in a table. No
two records in a table should have the same values in every field. For example, the following
should not occur in a table.
Last Name
First Name
City
Smith
John
Jonestown
Smith
John
Jonestown
In the real world, it is possible to have two people from the same city with the same first and last
name. In cases like this, you can use the ID field as the primary key field and use it to make
each record unique. The ID field has a data type of AutoNumber; as a result, Access
automatically creates a unique number for each record in the database. The resulting table will
look like the one shown here.
ID
Last Name
First Name
City
Smith
John
Jonestown
Smith
John
Jonestown
Access provides several methods for creating a table. One method is to use the Rename option
with the Add New Field column label to give each column the field name you want it to have and
then to type or paste your data into the table. Field names can include letters, numbers, and
spaces and can be up to 64 characters long. When choosing a field name, try to keep it short.
When you save your table for the first time, Access gives you the opportunity to name your
table. Each table name must be unique; hence, two tables in the same database cannot have
the same name. The table name should describe the data in the table; can consist of letters,
numbers, and spaces; and can be up to 64 characters long. When choosing a table name, try to
keep it short.
You can save a table by clicking the Save button on the Quick Access toolbar or by right-clicking
the Tables tab and then choosing Save from the menu that appears.
1. Click the Save button on the Quick Access toolbar. The Save As dialog box appears.
Type the name you want to give your table.
2. Click OK. Access names your table.
9. Press the Tab key. Access moves to the Field Name field.
10. Repeat steps 3 through 10 until you have created all of your fields.
Access will switch to Query Design view. In the Show Table dialog box that appears, select the
table you would like to run a query on. We are running a query about our customers, so we'll
select the Customerstable.
In our example, we want to mail invitations to customers who live in a certain area, so we'll
include the FirstName, Last Name, Street Address, City, and Zip Code fields. We aren't planning
on calling or emailing our customers, so we don't have to include the Phone
Number or Email fields.
Set the search criteria by clicking on the cell in the Criteria: row of each field you would like to
filter. Typing criteria into more than one field in the Criteria: row will set your query to include
only results that meet all criteria. If you want to set multiple criteria but don't need the records
shown in your results to meet them all, type the first criteria in the Criteria: row and additional
criteria in the or: row and the rows beneath it.
Some customers who live in the suburbs live fairly close by, and we'd like to invite them as well.
We'll add their zip code, 27513, as another criteria. Because we want to find customers who
either live in Raleigh orin the 27513 zip code, we'll type "27513" in the or: row of the Zip
Code field.
After you have set your criteria, run the query by clicking the Run command on the Design tab.
The query results will be displayed in the query's Datasheet View, which looks like a table. If
desired, saveyour query by clicking the Save command in the Quick Access toolbar. When
prompted to name it, type in the desired name, then click OK.
Now you know how to create the simplest type of query with only one table. In the next lesson,
you'll learn how to create a query that uses multiple tables.
Access will switch to Query Design view. In the Show Table dialog box that appears, select the
table you would like to run a query on. We are running a query about our customers, so we'll
select the Customerstable.
In our example, we want to mail invitations to customers who live in a certain area, so we'll
include the FirstName, Last Name, Street Address, City, and Zip Code fields. We aren't planning
on calling or emailing our customers, so we don't have to include the Phone
Number or Email fields.
Set the search criteria by clicking on the cell in the Criteria: row of each field you would like to
filter. Typing criteria into more than one field in the Criteria: row will set your query to include
only results that meet all criteria. If you want to set multiple criteria but don't need the records
shown in your results to meet them all, type the first criteria in the Criteria: row and additional
criteria in the or: row and the rows beneath it.
2.For this one-table query, we'll use simple search criteria.
We want to find our customers who live in the city of Raleigh, so in our City field we'll
type "Raleigh". Typing "Raleigh" in quotation marks will retrieve all records with an exact
match for "Raleigh" in the City field.
Some customers who live in the suburbs live fairly close by, and we'd like to invite them as well.
We'll add their zip code, 27513, as another criteria. Because we want to find customers who
either live in Raleigh orin the 27513 zip code, we'll type "27513" in the or: row of the Zip
Code field.
After you have set your criteria, run the query by clicking the Run command on the Design tab.
The query results will be displayed in the query's Datasheet View, which looks like a table. If
desired, saveyour query by clicking the Save command in the Quick Access toolbar. When
prompted to name it, type in the desired name, then click OK.
Now you know how to create the simplest type of query with only one table. In the next lesson,
you'll learn how to create a query that uses multiple tables.
The Field List pane will appear. Double-click the desired field(s).
You can also use the above procedure to add fields to a totally blank form. Simply create a
form by clicking the Blank Form command on the Create tab, then follow the above steps to add
the desired fields.
Select the Create tab on the Ribbon. Locate the Reports group, then click the Report command.
To save your report, click the Save command on the Quick Access toolbar. When prompted,
type a namefor your report, then click OK.
Just like tables and queries, reports can be sorted and filtered. Simply right-click the field you
wish to sort or filter, then select the desired option from the menu.
2.Deleting fields
You might find that your report contains some fields you don't really need to view. For instance,
our report contains the Zip Code field, which isn't necessary in a list of orders. Fortunately, you
can delete fields in reports without affecting the table or query where you grabbed your data.
To delete a field in a report:
Click any cell in the field you would like to delete, then press the Delete key on your keyboard.
From the Home tab, click the View command, then select Print Preview from the drop-down list.
Your report will be shown as it will appear on the printed page.
If necessary, modify the page size, margin width, and page orientation using the related
commands on the Ribbon.
The Print dialog box will appear. Set any desired print options, then click OK.
The report will be printed.
4.Saving reports
You can save reports in other formats so they'll be viewable outside of Access. This is
called exporting a file, and it allows you to view and even modify reports in other formats and
programs.Access offers options to save your report as an Excel file, text file, PDF, HTML
document, and more. Experiment with the different export options to find the one that best suits
your needs.
You will see selected tables/queries small windows with columns names in Relationships
window. Now sit back start pondering over the selected tables to relate them properly. In this
example I am using only four tables (AddictiveTips Example, Courses, Lecturer, Mark Sheet).
You will see one-many relationship created between AddictiveTips Examples ID and course
code.
4.Creating the junction table
In this case there are two ways of linked products to orders. We can create a junction table with
ansurrogate primary key field, like the ID Autonumber field Access automatically provides.
We can also create our own composite primary key that consists of the two foreign key field in
the junction table. I will show you both ways and discuss the implications of each solution.
Create the junction table using a surrogate key
The junction table with surrogate primary key will have three fields, including the ID primary key
field that Access automatically creates for you. The two non-primary key fields are foreign keys.
They will reference the primary keys of the Order and Product tables (or perhaps some other
tables in your case).
Create a new table and name it something like LeftTable2RightTable. In my example I named it
Order2Product. This notation is often chosen for junction tables.
Go to the design view of your new table (Read how to create a table in Access 2010 if you need
more info on creating tables in design view).
Leave the automatically supplied ID primary key field in tact. Add two new fields. In my example
I created order and product fields. The order field will reference the primary key of the Order
table. The product field will reference the primary key of the Product table.
Make sure your fields are of the same data type as the primary key fields they will reference.
The example below is a finished junction table with some data. The order and product fields are
both of the Number type, because they both refer to an Autonumber primary key field, which is
in fact a Number field that is managed by the database.
In the Relationships screen, add the three tables you want to create the many-to-many
relationship with to the screen. You can do this by dragging tables from the left onto the screen
or by using the Show Table window, which is accessible via the Show Table button on the
ribbon.
When your tables are on the Relationship screen drag the primary key fields of the entity tables
(Order and Product in this example) to their counterparts in the junction table.
When you drag and drop a primary key field onto a field in another table, Access knows you
want to create a relationship and it brings up the Edit Relationships window. This is where you
create the actual relationship. In order to create a many-to-many relationship you must
create two one-to-many relationships.
Create a one-to-many relationship between both your entity tables (Product and Order in this
example) and the junction table. Select all three integrity options (Note: the integrity options are
discussed in the article Create a one-to-many relationship in Access).
When both one-to-many relationships are created you have really created a many-to-many
relationship, because a many-to-many relationship is made of two one-to-many relationships.
The end result should look like this: