You are on page 1of 4

Ms Access Mallarpur Youth Computer Training Center

Database
A database is a collection of files. A Database Management System (DBMS) is a program (set of programs) that stores and
organizes data.  One such organization method is relational where data is organized by means of related tables called relations and
hence the name Relational Database Management System (RDBMS).  RDBMS stores information in related relations (tables,
subjects) which can be related using common fields.

Tables Object
RDBMS stores information about subjects in tables called relations (each relation contains information about one subject, i.e.,
Students).  Tables are the foundation for any database management system.  Tables are used to store data values and information
about subjects.  For example we can create a table that stores information about students, customers, products, orders, books, etc.  In
MS Access a table consist of rows and columns of related data.
A row also referred to as record is a set of related data values. Columns on the other hand contain information about a unique
attribute of one entity (StudentID, StudentName, StudentGPA). Columns are refereed to as fields which are identifiers for individual
pieces of data, each column represent one attribute. A table is made of rows (records) and columns (fields).
RDBMS is a collection of related tables (also refereed to as relations). Each relations is identified by its key attribute. A key is a
field in the relation that uniquely identifies an entity (for example StudentID is a key in the Student relation as it uniquely identifies
a student).

Fields Data Types


Access supports the following data types
Data type Description Example
Text A Text field can store any character or number up to 255 characters. Student Name
Number A Number field can store numbers. Student GPA
Date/Time A Date/Time field stores a date and a time. Graduation Date
Student Balance
Currency A Currency field stores currency values, numbers, and decimal-place formatting.
(Tuition)
AutoNumbe
An AutoNumber field stores serial or random numbers assigned by Access, can't be updated. Student ID
r
An OLE object field stores objects created by programs other than Access and linked to or
OLE Object Student Photo
embedded in an Access table.

Primary Key
The power of a relational database system such as Microsoft Access comes from its ability to quickly find and bring together
information stored in separate tables using queries, forms, and reports. In order to do this, each table should include a field or set
of fields that uniquely identifies each record stored in the table. This information is called the primary key of the table. Once you
designate a primary key for a table, Access will prevent any duplicate or Null values from being entered in the primary key fields.

Primary key , are fields in the table that uniquely identifies a record. One or more fields whose values uniquely identify each
record in a table. Null values are not allowed in a primary key and a primary key must always have a unique index. A primary key is
used to relate a table to foreign keys in other tables.
Foreign Key, One or more table fields that refer to the primary key field in another table. A foreign key indicates how the tables are
related.

-1-
Ms Access Mallarpur Youth Computer Training Center

Relationships
Relationships are used to extract information form multiple tables (i.e., to join one more tables).  Primary and forign keys are used
to join tables in one of the following forms of relations:
1. one-to-one relationship, when one record in the first table relate to one and only one record in the related table (foreign
key).
2. one to many relationship, when one record in the primary table is related to many records in the related table.  this is the
most common relationship.  For example there is a one to many relationship between Student table and the Courses table
since each student can register for multiple classes.
3. many to many relationship, when many records in one table are related to many records in the related table.  For example
table Orders has a one to many relationship with table Orders.  MS Access does not support many-to-many relationship ,
we can implement it in access by breaking the relationship into two one to many relationships using Junction tables. 
Junction tables are tables that are used to to link two tables in a many-to-many relationship by including the primary keys
from both tables.

Define relationships between tables


When you create a relationship between tables, the related fields don't have to have the same names. However, related fields must
have the same data type unless the primary key field is an AutoNumber field. You can match an AutoNumber field with a
Number field only if the FieldSize property of both of the matching fields is the same. For example, you can match an AutoNumber
field and a Number field if the FieldSize property of both fields is Long Integer. Even when both matching fields are Number
fields, they must have the same FieldSize property setting.

One to one or One to many relationships

1. Close any tables you have open. You can't create or modify relationships between open tables.
2. Click Relationships on the toolbar.
3. If you haven't yet defined any relationships in your database, the Show Table dialog box is automatically displayed.
If you need to add the tables you want to relate and the Show Table dialog box isn't displayed, click Show Table on the
toolbar.
4. Double-click the names of the tables you want to relate, and then close the Show Table dialog box. To create a
relationship between a table and itself, add that table twice.
5. Drag the field that you want to relate from one table to the related field in the other table.
To drag multiple fields, press the CTRL key, click each field, and then drag them.
In most cases, you drag the primary key field (which is displayed in bold text) from one table to a similar field (often with
the same name) called the foreign key in the other table.
6. The Edit Relationships dialog box is displayed. Check the field names displayed in the two columns to ensure they are
correct. You can change them if necessary.
Set the relationship options if necessary. For information about a specific item in the Edit Relationships dialog box, click
the question mark button, and then click the item.
7. Click the Create button to create the relationship.
8. Repeat steps 5 through 8 for each pair of tables you want to relate.
When you close the Relationships window, Microsoft Access asks if you want to save the layout. Whether you save the
layout or not, the relationships you create are saved in the database.
Note:   You can create relationships using queries as well as tables.
-2-
Ms Access Mallarpur Youth Computer Training Center
Many to many relationhip
many-to-many relationship: An association between two tables in which one record in either table can relate to many records in the
other table. To establish one, create a third table and add the primary key fields from the other two tables to this table.)

1. Create the two tables that will have a many-to-many relationship.


2. Create a third table, called a junction table, and add to the junction table new fields with the same definitions as the
primary key fields from each of the other two tables. In the junction table, the primary key fields function as foreign keys.
You can add other fields to the junction table, just as you can to any other table.
3. In the junction table, set the primary key to include the primary key fields from the other two tables. For example, in an
Order Details junction table, the primary key would be made up of the OrderID and ProductID fields.

About forms
A form is a rectangular object used to host, carry, or hold other objects that serve for interaction between a user and the database
application. As such,  a form by itself means nothing. The objects positioned on it play the main role. As a normal Microsoft
Windows window, a form shares many of the characteristics of other containers.

Reports
A report is an effective way to present your data in a printed format. Because you have control over the size and appearance of
everything on a report, you can display the information the way you want to see it.
Report Printing
As stated already, the report is the favorite object used to print data. As done with the other objects, you can print a report whether it
is opened or not. Before printing a report, you must first select or open it. If you want to print a report without opening it, in the
Database window, make sure the Reports section is selected. Then, you can locate and right-click the desired report. If you follow
this approach, the report would be sent directly to the printer.
If you want to control or customize the printing of a report, first select it in the Reports section of the Database window or open it.
Then, on the main menu, you can click File -> Print… This would display the Print dialog box, allowing you to select a printer if
you have more than one. You can also specify such aspects as the color, the number of copies or the range of records to be printed.

Queries
To interrogate a collection of data such as records in a database. The term may also be used to search a single file or collection of
files such as HTML files on the Web. However, in addition to obtaining lists of records that match the search criteria, queries to a
database allow for counting items and summing amounts. A query on the Web yields only a list of matching pages and is more often
called a "search."

Tables Must Be Joined


Relational databases are designed to eliminate redundancy. The goal is to store a data item in one table and not have it duplicated in
others. For example, an order record will contain the product number ordered, but often not its description. The description is stored
in a product table. Thus, any printout of products ordered and their descriptions requires that the order table be linked to the product
table for that query or report. Linking customer, order and product tables is a common example of "joining" tables to satisfy a
query.

Contents of a Query
Most queries require at least the following conditions to be stated. First, which table or tables is the data coming from. If from two
or more tables, what is the link between (typically account number or name). Next, define the selection criteria, which is the
matching condition or filter. Lastly, define which fields in the tables are to be displayed or printed in the result.

About designing a query


When you open a query in Design view, or open a form, report, or datasheet and show the Advanced Filter/Sort window, you see
the design grid, which you can use to make a variety of changes to get the query results you want.

Criteria
Conditions you specify to limit which records are included in the result set of a query or filter. For example, the following criterion
selects records for which the value for the Order Amount field is greater than 30,000: Order Amount > 30000

-3-
Ms Access Mallarpur Youth Computer Training Center
About types of queries
Select queries
A select query is the most common type of query. It retrieves data from one or more tables and displays the results in a datasheet
where you can update the records (with some restrictions). You can also use a select query to group records and calculate sums,
counts, averages, and other types of totals.

Parameter queries
A parameter query is a query that when run displays its own dialog box prompting you for information, such as criteria for
retrieving records or a value you want to insert in a field. You can design the query to prompt you for more than one piece of
information; for example, you can design it to prompt you for two dates. Access can then retrieve all records that fall between those
two dates.
Parameter queries are also handy when used as the basis for forms, reports, and data access pages. For example, you can create a
monthly earnings report based on a parameter query. When you print the report, Access displays a dialog box asking for the month
that you want the report to cover. You enter a month and Access prints the appropriate report.

Crosstab queries
You use crosstab queries to calculate and restructure data for easier analysis of your data. Crosstab queries calculate a sum, average,
count, or other type of total for data that is grouped by two types of information  — one down the left side of the datasheet and
another across the top.

Action queries
An action query is a query that makes changes to or moves many records in just one operation. There are four types of action
queries: 
Delete Queries   A delete query deletes a group of records from one or more tables. For example, you could use a delete query to
remove products that are discontinued or for which there are no orders. With delete queries, you always delete entire records, not
just selected fields within records.
Update Queries   An update query makes global changes to a group of records in one or more tables. For example, you can raise
prices by 10 percent for all dairy products, or you can raise salaries by 5 percent for the people within a certain job category. With
an update query, you can change data in existing tables.
Append Queries   An append query adds a group of records from one or more tables to the end of one or more tables. For example,
suppose that you acquire some new customers and a database containing a table of information on those customers. To avoid typing
all this information into your own database, you'd like to append it to your Customers table.
Make-Table Queries   A make-table query creates a new table from all or part of the data in one or more tables. Make-table queries
are helpful for creating a table to export to other Microsoft Access databases or a history table that contains old records.
SQL queries
An SQL query is a query you create by using an SQL statement. You can use Structured Query Language (SQL) to query, update,
and manage relational databases such as Access.
When you create a query in query Design view, Access constructs the equivalent SQL statements behind the scenes for you. In fact,
most query properties in the property sheet in query Design view have equivalent clauses and options available in SQL view. If you
want, you can view or edit the SQL statement in SQL view. However, after you make changes to a query in SQL view, the query
might not be displayed the way it was previously in Design view.
Some SQL queries, called SQL-specific queries, can't be created in the design grid. For pass-through, data-definition, and union
queries, you must create the SQL statements directly in SQL view. For subqueries, you enter the SQL in the Field row or the
Criteria row of the query design grid.

Table Importing

click File -> Get External Data -> Import.


From there, you can select the category and the objects you want to import, then click OK.

Table Linking
Another technique used to use external data consists of linking to it instead of importing. This allows the original application to
preserve its data and only make it available to your database.
To link to external data, you can first call the New Table dialog box. From there, you can click Link Table and click OK or you can
double-click Link Table. Alternatively, on the main menu, you can click File -> Get External Data -> Link Tables... This would call
the Link dialog box. You can then select the application that holds the data you want and click Link. You would be presented with a
Link Tables dialog box.
This gives you the opportunity to select the table(s) and click OK.
When linking to an external table, since the table actually belongs to another application, file, or database, you should not change
characteristics of its fields.

-4-

You might also like