You are on page 1of 28

QUESTION/DISCUSSION

1.How to create a table


1.Understanding Tables
A table is a set of columns and rows. Each column is called a field. Within a table, each field
must be given a name and no two fields can have the same name. Each value in a field
represents a single category of data. For example, a table might have three fields: Last Name,
First Name, and Phone Number. The table consists of three columns: one for last name, one for
first name, and one for phone number. In every row of the table, the Last Name field contains
the last name, the First Name field contains the first name, and the Phone Number field
contains the phone number. Each row in a table is called a record.

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.

2.To add fields to a table:

1. Click the Add New Field column label.


2. Activate the Datasheet tab.
3. Click Rename in the Fields & Columns group.
4. Type the field name.
5. Press Enter. Access creates the field.
6. Type the next field name. Access creates the field. Continue until you have created all of
the fields in your table.
7. Press Enter without entering a field name to end your entries.
Or
1. Right-click the Add New Field column label. A menu appears.
2. Click Rename Column.
3. Type the field name.
4. Press Enter. Access creates the field.
5. Type the next field name. Access creates the field. Continue until you have created all of
the fields in your table.

3.Name and Save a Table


After you create a table, you must name and save it.
To name and save a table:

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.

4.To use Design view to create a new table:

1. Activate the Create tab.


2. Click Table Design in the Tables group. Access changes to Design view and the Table
Tools become available.

3. Type the first field name in the Field Name field.


4. Press the Tab key.
5. Click the down-arrow that appears when you click in the Data Type field and then select
a data type.
6. Click Primary Key if the column you created is a primary key. A small key appears next
to the field name.
7. Press the Tab key.
8. Type a description. The description is optional.

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.

5.To use the Lookup Wizard to create a lookup column:


Open the Lookup Wizard

1. Open the table to which you want to add a lookup column.


2. Click the field label for the field before which you want to add a lookup column.
3. Activate the Datasheet tab. (You must be in Datasheet view.)
4. Click the Lookup Column button in the Fields & Columns group. The Lookup Wizard
appears.
5. Make sure the radio button next to I want the lookup column to look up the values in a
table or query. is selected.

6. Click Next. The Lookup Wizard moves to the next page.

2.How to create a Query

1.How are queries used ?


Queries are far more powerful than the simple searches or filters you might use to find data
within a table. This is because queries can draw their information from multiple tables. For
example, while you could use a search in the customers table to find the name of one customer
at your business or a filter on the orders table to view only orders placed within the past week,
neither would let you view both customers and orders at once. However, you could easily run
a query to find the name and phone number of every customer who's made a purchase within
the past week. A well-designed query can give information you might not be able to find out just
by examining the data in your tables.
When you run a query, the results are presented to you in a table, but when you design one you
use a different view. This is called Query Design view, and it lets you see how your query is put
together.

2.To create a simple one-table query:


Select the Create tab on the Ribbon, and locate the Queries group.
Click the Query Design command.

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.

Click Add, then click Close.


The selected table will appear as a small window in the Object Relationship pane. In the table
window, double-click the field names you would like to include in your query. They will be added
to the Design Gridin the bottom part of the screen.

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.

3.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.

3.How to create a Form


1.To create a simple one-table query:
Select the Create tab on the Ribbon, and locate the Queries group.
Click the Query Design command.

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.

Click Add, then click Close.


The selected table will appear as a small window in the Object Relationship pane. In the table
window, double-click the field names you would like to include in your query. They will be added
to the Design Gridin the bottom part of the screen.

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.

3.To add a field to a form:


Select the Design tab, then locate the Tools group on the right side of the Ribbon.
Click the Add Existing Fields command.

The Field List pane will appear. Double-click the desired field(s).

The field will be added.

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.

4.To add a field from a different table:


You can also add fields from different tables in your database to the form.
From the Field List pane, click Show All Tables.
Click the plus sign + next to the table that contains the field you wish to add, then double-click
the desired field.

The new field will be added.

4.How to create a Reports


1.To create a report:
Reports give you the ability to present components of your database in an easy-to-read,
printable format. Access lets you create reports from both tables and queries.
Open the table or query you would like to use in your report. We want to print a list of cookies
we've sold, so we'll open the Cookies Sold query.

Select the Create tab on the Ribbon. Locate the Reports group, then click the Report command.

Access will create a new report based on your object.


It's likely that some of your data will be located on the other side of the page break. To fix
this, resize your fields. Simply select a field, then click and drag its edge until the field is the
desired size. Repeat with additional fields until all of your fields fit.

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.

The field will be deleted.


When you delete a field, be sure to delete its header as well. Simply select the header and
press theDelete key.

3.To print a report:


Click the buttons in the interactive below to learn about Print Preview.

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.

Click the Print command.

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.

5.How to create a Relationship


One of the advantages of Relational Database Management System such as Access 2010 is to
easily setup tables and relationships with constraints to make them more tightly followed. One
feature is being the ability to create and maintain relationships between tables.
1.To start create a relationsip table
To start off with, Launch Access, create tables for defining relationships among them.For
Instance, I am using an existing database with tables (primary keys assigned and data types
with constraints applied ). Launch Access 2010, navigate to Database Tools on new Access
ribbon and click Relationships button.

2.Make a colomns names in table


Access will open Relationships tab with Show Table Dialog box. Select tables, queries or both,
and hit Add.

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).

3.Creating many one relationship


I am now creating one-many-relationship between AddictiveTips Example (Student)
and Courses table. Click & hold the primary key of AddictiveTips Example, drag it and drop
over course name in small window of Courses. Immediately Edit Relationships dialog window
will pop-up. Here you can create new relationship between tables, Specify Join Type, and
Enforce Referential Integrity. For demonstration purpose, I am going to ignore all options and
hit Create.

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.

5.Create the actual relationships


The final steps in creating the many-to-many relationship is creating the actual relationships in
the Relationships view. Creating a many-to-many relationship is a matter of creating two one-tomany relationships. Here is how you do it.
Open the Relationship view by going to the Database Tools tab on the ribbon and selecting the
Relationships button.

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:

You might also like