
- •Context
- •Introduction
- •1 Creating and working with a database in ms access 2003
- •1.1 Introduction to Databases
- •1.2 Planning a Database
- •1.3 Starting Access and Opening a Database
- •1.4 Self-control test
- •2 Creating a table in ms access 2003
- •2.1 Theoretical material
- •2.2 Example of tables creation for database “Product realization of Holding company “Group nord”
- •2.3. Self-control test
- •3 Creating queries in ms access 2003
- •3.1 Theoretical material
- •3.2 Example of queries creation for database “Product realization of Holding company “Group nord”
- •3.3. Self-control test
- •4 Creating forms in ms access 2003
- •4.1 Theoretical material
- •4.2 Example of forms creation for database “Product realization of Holding company “Group nord”
- •4.3. Self-control test
- •5 Creating reports in ms access 2003
- •5.1 Theoretical material
- •5.2 Example of reports creation for database “Product realization of Holding company “Group nord”
- •5.3. Self-control test
- •Individual tasks
- •Variant 1
- •Information about passengers
- •Variant 2
- •Variant 3
- •Variant 4
- •Variant 5
- •Variant 6
- •Variant 7
- •Variant 8
- •Variant 9
- •Variant 10
- •Variant 11
- •Vehicles
- •Variant 12
- •Variant 13
- •Variant 14
- •Information about printing-house
- •Variant 15
- •Variant 16
- •Literature
2.3. Self-control test
No |
Question |
Check off the right box |
1. |
Tables are used for: |
|
|
|
|
|
|
|
|
|
|
|
|
|
2. |
Define the way of tables creation |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3. |
“Design view” button opens: |
|
|
|
|
|
|
|
|
|
|
|
|
|
4. |
A property of automatically inserting have a field type: |
|
|
|
|
|
|
|
|
|
|
|
|
|
5. |
Text field allows to enter information up to: |
|
|
|
|
|
|
|
|
|
|
|
|
3 Creating queries in ms access 2003
Purpose: to get practical skills of queries creating for relational database in MS Access 2003.
3.1 Theoretical material
Queries can be used to quickly analyze and sort information that is in an Access database. A query allows you to present a question to your database by specifying specific criteria. A query can be based on tables or on other queries.
Queries allow you to specify:
The table fields that appear in a query.
The order of the fields in a query.
Filter and sort criteria for each field in a query.
Select queries are the most commonly used type of queries in Access. They allow you to choose which fields and records to display in a new datasheet. Other types of queries include crosstab queries and four types of action queries.
Queries have two views: Design view and Datasheet view. In the Design view, you specify which fields you want to see, which tables they come from, and the criteria that records have to meet in order to appear on the resulting database. Criteria are tests that records have to pass. In the Query Datasheet view, you view the records that are found to meet your criteria.
When you run a query, Access pulls data out of tables and puts the data in a database for you to see. The original table and database stay connected, so that if you make changes to the data on your database, the results of the query also change. When you save a query, you save the query design, rather than the results, so that you can ask the same questions again.
A select query can be used to select certain data from a table or tables. It basically filters and sorts the data and can perform simple calculations, such as summing and averaging.
An easy way to create a select query is to use the Simple Query Wizard. It allows you to select the table fields you want to include in a query. This type of query is very useful when you want to eliminate extra fields, but still want to view every record in a database table.
A limitation of the Simple Query Wizard is that it does not allow you to set sorting parameters for records in order to sort by particular criteria, such as less than, greater than, equal to, etc. You must use a create a query from scratch in order to be able to set parameters.
Microsoft Access allows for many types of queries, some of the main ones being select, action, parameter and aggregate queries.
The select query is the simplest type of query and because of that, it is also the most commonly used one in Microsoft Access databases. It can be used to select and display data from either one table or a series of them depending on what is needed.
In the end, it is the user-determined criteria that tells the database what the selection is to be based on. After the select query is called, it creates a "virtual" table where the data can be changed, but at no more than one record at a time.
Action Query. When the action query is called, the database undergoes a specific action depending on what was specified in the query itself. This can include such things as creating new tables, deleting rows from existing ones and updating records or creating entirely new ones.
Action queries are very popular in data management because they allow for many records to be changed at one time instead of only single records like in a select query.
Four kinds of action queries are:
Append Query – takes the set results of a query and "appends" (or adds) them to an existing table.
Delete Query – deletes all records in an underlying table from the set results of a query.
Make Table Query – as the name suggests, it creates a table based on the set results of a query.
Update Query – allows for one or more field in your table to be updated.
Parameter Query. In Microsoft Access, a parameter query works with other types of queries to get whatever results you are after. This is because, when using this type of query, you are able to pass a parameter to a different query, such as an action or a select query. It can either be a value or a condition and will essentially tell the other query specifically what you want it to do.
It is often chosen because it allows for a dialog box where the end user can enter whatever parameter value they wish each time the query is run. The parameter query is just a modified select query.
Aggregate Query. A special type of query is known as an aggregate query. It can work on other queries (such as selection, action or parameter) just like the parameter query does, but instead of passing a parameter to another query it totals up the items by selected groups.
It essentially creates a summation of any selected attribute in your table. This can be further generated into statistical amounts such as averages and standard deviation, just to name a couple.
The SQL aggregate functions available to Microsoft Access are Sum, Avg, Min, Max, First, Last, Group By, Count, StDev, Var, Expression, Where.
Note - Queries don’t actually run while you are in datasheet mode, because it is essentially a preview of the application.
Creating a Query in Design View
In the Database window, click the Queries icon in the Objects bar and double-click Create query in Design view.
The Show Table dialog box appears, as shown in figure 3.1. Here you have to select the table or query you want to use.
Figure 3.1 – The Show Table dialog box
When you have finished adding the tables or queries to your new query, you can close the Show Table dialog box (click Close).
The Query window appears in Design view. Notice that the window is split. The top half contains a boxes, which display all the fields in the you tables. The bottom half of the screen contains a design grid, which is where you will add the fields you want to appear in your query.
You can add fields to the design grid in two ways:
By double-clicking the field in the field list.
By clicking and dragging the field down to the design grid.
Figure 3.2 – The Query window in Design view
Often you will have to use the field list's scroll bar to scroll up or down the list in order to find a field. Then you need to specify any criteria for the query. You enter the criteria in the design grid's Criteria row.
If you want to use a field in the query, but you don't want it to be displayed in the query results, uncheck the "Show" box for that field. Your design grid should look like figure 3.3.
Figure 3.3 – An example of a query in design grid view
To
run a query you should click the
Run
button on the toolbar.
Other
ways to run a query are to open the Query from the Database window,
or click the
Datasheet
View button on the toolbar.
You can also select Query Run from the menu. Access displays the results of the query.
In general, the fields that are displayed in a set of query results, have properties that are specified for the corresponding fields in the table. You can define other property values by executing Properties from the View menu.
To delete a field from query blank press [Delete] or use menu Edit → Delete columns.
Table 3.1 - Basic operators
Operator |
Description of the use |
And |
finds vales that correspond to several criteria. Example, >2 and <5 |
Or |
finds vales that correspond to at least one criterion. Example: 10 or 15 |
< > |
finds vales not equal to X Example: <>10 |
Between |
To find values in a range of numbers Example: between 10 and 20 |
In |
Determines whether a value is found within a set of values. Example: in (“first”,”second”,”third”) |
Like |
Matches string values by using the wildcard operators ? and *. The asterisk (*) represents any string of text from nothing up to an entire paragraph or more. The question mark (?) represents a single character only (although you could use, for example, two question marks to represent two unknown characters) For example:
|
# |
When you enter a date in the criteria cell you can use any standard date format, but each date must be enclosed by hash marks (#). For example:
|
In DBMS Access also we use other functions, which help us to set criteria for date and time:
Day([date]) – returns a value of day in a range from 1 to 31.
Month([date]) – returns a value of month in a range from 1 to 12.
Year([date]) – returns a value of year in a range from 100 to 9999.
Date() – contains today's date.
In addition to the normal querying, Access allows you to create mathematical calculations based on numeric fields. For example, if you have an existing field containing car prices, you may want to see what a 5% increase would look like before actually editing each record and permanently changing its contents.
The following mathematical operators can be used:
+ Addition
- Subtraction
* Multiplication
/ Division
^ Involution
& Concatenation - connection parts of the text, for example
=[First_name] & “ “&[Last_name]
You can create calculations on numeric, $ and date fields.
You place your mathematical expression in the "Field" cell (you can use Build…).
Also, if you are using other fields in the calculation, you must place square brackets [ ] around the field name of the other field so that Access knows where to get the data from.
A "crosstab query" in Microsoft Access 2003 compresses selected data into a viewable space. This allows you to quickly locate values and trends. Crosstab queries are useful for summarizing information, calculating statistics, spotting bad data and looking for trends. The results of a crosstab query are read-only — data cannot be added, edited or deleted in a crosstab result. An aggregate function, such as sum or count, is used to help summarize the data.
To Create a Crosstab Query click "Design View" in the dialogue box, and then select "OK" to confirm your choice. Select "Show Table" to view the tables you want to add to your query. Double-click the objects you want to put in your query, then click "Close". Under "Query Type" in the top toolbar select "Crosstab" in the dropdown menu. Designate the fields you want to appear as rows in the grid by clicking the "Crosstab" row, then "Row Heading". Do the same for the fields that will appear as columns by clicking on "Column Heading". Select your final field--the one you will use for cross-tabulation by clicking on the "Crosstab" row, then clicking "Value" to this field. To view your final crosstab query, click the "View" icon on the top toolbar.