You are on page 1of 42

MS Access

A. R. Dani

Basics
DBMS : Data Base Management Systems. DBMS: An abstraction of an enterprise related to an enterprise It is used to store data of the enterprise Data: Transactional Data and other type of data DBMS: Allows enterprise to store, retrieve, update, delete and backup the data. Life Cycle of Data: C Store, Retrieve, Update, Backup and Delete The alternative to DBMS was File System In File System, data are stored in one or more data files. Data Files can be of different types.

Basics
Problem with File System Redundancy of Data Same data in different files Access through Programmers (no SQL like access) Sharing data among different users is difficult Explicit locking by programmers Difficult to answer adhoc queries Many data files are created. Explosion of files Update problems No centralized control Access controls has to be implemented by programmers Files are created for specific purposes in most cases as such are specific for the purpose for they are created Time to develop applications

Basics
DBMS Designed taking into account enterprise view Centralized Control Access Controls enforced by DBMS Reduce Data Redundancy Developed for Data Sharing SQL can be used to store data, retrieve data and update data Automatic backup and recovery features Programming Languages access through standardized DBMS interface Easy to applications. Many tools are available Manage large volume of data

RDBMS
Relational Data Base Management System (RDBMS) RDBMS: It views data as collection of tables. A Table has row and columns (two dimensional structure) Entity Relationship Diagrams are used to model tables A row represents record A column represent an attribute Primary Key Different tables can be related by table values Primary Keys, Foreign Keys RDMS Design: Reduce data redundancy and update anomalies Data Normalization Referential Integrity

MS Access is part of MS Office It can be used to store data As such there is overlap with some other products available in MS Office and from other vendors Although there is always overlap, the following rules might help when deciding when / when not to use MS Access: MS Access is best used for long-term data storage and/or data sharing. MS Excel is best used for minor data collection, manipulation, and especially visualization. SPSS is best used for minor data collection and especially data analysis. It is easy to export data from MS Access to Excel SPSS

MS Access

Cheap, readily available (packaged with MS-Office Premium). Easy to use (relative to other systems ) Easy to use Interface Wizards Oracle may require one Engineer to maintain the server as a database administrator It also requires another engineer to serve as an application developer MS Access Includes front-end tools for rapid application development (RAD). This also makes MS-Access a good prototype environment. All programming languages can use it.

MS Access

MS Access
MS-Access can handle a large number of records, but is somewhat slow compared to some of the high-end platforms. Multiple users may use the database simultaneously, but MSAccess is known to become unstable with greater than 3-5 users. MS Access is used by smaller companies It is also used as Database for small applications In case of complex multi users applications, which have to handle large number of record , the other RDBMS will be preferred. ORACLE/DB2 are preferred choices for complex enterprise applications MS Access Learning

MS Access
Although the term database typically refers to a collection of related data tables, an Access database includes more than just data. In addition to tables, you can add: Saved queries (stored procedures) - organizing and/or manipulating data Forms gui interaction with data, event programming Reports customized results for printing (~ static forms) Macros and VB programs for extending functionality Microsoft provides some logical integration of these tools through wizards. However, these are pretty basic - most developers must pick and choose the best approach when implementing applications.

MS- Access File


Unless advanced techniques are employed, all entities are stored in one *.mdb file. When running, a locking file (*.ldb) is also visible. Only the mdb file needs to be copied to transfer the database to another computer or location. Ex.
MSCI_ByrneGuestLecture.mdb

MS Access File
VB + Macros Event Driven Automation, etc.

Forms (Active)

Reports (Static)

Queries

Tables Demographics Ethnicity Labs H&P

Applications
Front-End File - Contains all Application Entities (Forms, Queries, etc.) and links to data tables in back-end file. Note you may have more than one FE to accommodate different user types.

VB + Macros Event Driven Automation, etc.

Forms (Active)

Reports (Static)

Queries Tables Demographics Ethnicity


Back-End File - Contains all Data Tables

Labs

H&P

MS Access and Objects


Relational data model Data is stored in tables incorporated into database files with extension mdb or accdb Standard Windows interface Standard Help system Part of MS Office suite Tables contain rows called records and columns called fields. Queries are requests for specific information from a database. Queries are virtual tables built on a given SQL statement

Forms are parts of user interface. Forms are used to enter, edit or browse data from a database Reports present requested information and allow to create hard copies. Microsoft Access is a relational database management system (DBMS or RDBMS). At the very core, it is a software engine that provides an interface between physical data and user application queries. Other examples of DBMS applications include: Oracle mySQL SQL Server (Microsoft) DB2 (IBM) Informix

MS- Access Objects

Tables Overview
Think of Access as a collection of

spreadsheets that are relationally linked.


STORE DATA ONE TIME / ONE PLACE DO NOT STORE CALCULATED DATA Demographics Patient_ID Fname Lname Address Phone Gender Race DOB Height Glucose Glucose_ID Patient_ID Date Weight Med_ID Glucose Meds Med_ID DrugCombonation

Data Types
Text Memo Numbers
Byte Integer Long integer Single Double

Currency AutoNumber Yes/No


Yes/no True/False 1/0

Date/time

OLE Objects Hyperlink Lookup Wizard

Create Table
Click on the round Office button Choose New from the drop-down menu In Create Blank Database window specify the database name Click Create Using Wizard Design View Specify field names Data types Properties Determine a primary key Save the table

Access Tables and Constraints


Design view Table structure is created and may be edited Datasheet view Display table content in spreadsheet-like grid, Used for entering, editing or deleting data from tables Referential Integrity Can be established or removed in Relationship window In MS Access 1995-2003 open menu Tools and choose Relationships from the drop-down menu In MS Access 2007 and up choose Database Tools tab and then Relationships Use drag-and-drop features and select Enforce Referential Integrity option Tip specify referential integrity constraints before data is entered

Tables

General Setup for Tables Describe General Options Show Validation Rule Relationships Lookup Option

Tables

Table Relationships

Describe Cascade Features

Table Import
Importing a Table makes a copy of existing data

Linking a Table lets you control existing data through Access (Exercise Caution !)

Note that you may import non-Access files.

Tables
Data storage principles Attempt to store data 1 time / 1 place; Do not store data that may be calculated from other fields (utilize queries); and Strive for very discrete data storage (no ambiguity garbage in / garbage out). Choose real or arbitrary (autonumber) unique identifier for each record. Relationships Use table relationships to automatically cascade delete and update records. Other Data Sources Import = Copy; Link

Query
Specify the source of data If multiple tables are used, specify relationships between tables Select desirable fields from the table(s) and options related to the fields Specify a criterion

To be selected a record must satisfy a criterion Expressions may contain the following operators:
Math Operators Relational operators Boolean Operators String Operators Miscellaneous Operators

Math Operators
+
*

Addition
Subtraction Multiplication

/
\ ^ Mod

Division
Integer Division Exponentiation Modulo (remainder) division

Relational Operators
= <> < > <= >= Equal Not equal Less than Greater than Less than or equal to Greater than or equal to

Boolean Operator
And
Or

Logical And
Logical Or

Both operands are true


Either one of the operands or both of them are true Only one of the operands (not both of them) are true Operand is not true

Xor

Excusive Or

Not

Negation

String and Miscellaneous Operators


&
Like

Concatenation
Similar to

Between Between 2 values inclusive and In (list) One from the list
Is Null True if the field is empty

Queries Retrieve Data SQL (Structured Query Language) is a very widely used

Query

database language designed specifically for communicating with databases SQL is not proprietary almost every DBMS supports SQL (including MS-Access). An MS-Access query is a set of stored SQL instructions that manipulate and/or select data from one or more tables. Select Query Data grouping and/or filtering Make-Table Query Select + creates/populates new table. Update Query Updates fields from specified table data Append Query Runs query on one table, appends results to a table Delete Query Delete selected records from table

Query

SQL is relatively easy to learn, but extremely powerful One of the easiest ways to learn is to use MS-Access Query by Example methods (QBE), It also generates corresponding SQL Statement . After QBE one can look at the generated SQL command Remember that a query is nothing more than the database engine running the stored SQL command It looks and sometimes acts like a table, but really adds little mass to the database file. In Query, Name the calculated field, then type a colon, then type the equation using brackets ( [ ] ) around table fields. If there is ambiguity in the field names between tables, you may need to type table.[field] format. Ex: BMI: [Weight]/([Height]/100)^2 Select , Insert , Delete, Update with where

Query Sorting Data

Choose Ascending or Descending in the Sort Row This query would sort by Gender THEN by Race.

Query Filtering Data


You need not show the data field to use as a filter.

This query will return all records in the database for: Females who are not white whose height are greater than 150 cm and who weigh between 60 and 70 kg

Query Grouping Data


Clicking the Totals Button Enables Grouping, Counting and Statistical Options

Running this Query indicates there are 203 Females and 261 Males in the database.

Notice new Total row. Each field (column) can be set.

Query Grouping Data


Totals Options Include: Group By Sum

Avg
Min Max Count StDev Var

Query Export Data


1)
Create and Save Query

2)

Use OfficeLinks (Excel Toggle Option) to Analyze it with Excel

3)

Data Automatically Exported to Excel

Query
Queries are extremely easy to set up/use They provide an up-to-date snapshot of your data at any time. Queries may be used to calculate values based upon existing fields, join fields from separate tables, globally update or delete data, and export linked/calculated data to external programs. Different types of joints The queries are really nothing more than stored SQL statements that are run upon command. They add little mass to the file application. If you use MS-Access its important should feature is to import data and export it.

Forms Although it is possible to enter data directly into a table, one


can enhance data quality by forcing data entry through forms. Depending upon the type of users, one may wish to set things up so they never even see the database window. In other words, one can design your application so they only touch the data through programmed forms. As an example one see that in case of the glucose database earlier slides one can attempt to build a graphical user interface to: Collect Data Periodically report data through pre-formatted reports Quit the program So the user will be unaware of the existence of table

GUI Forms

Out of Program

Create using Form Wizard Create using Form Design view Specify source of data will be presented by the form Table Query Specify fields related to the form Add labels, titles, graphics and so on Form Design View : Form Header a place for titles, graphics, additional information Form Details section the fields used to create a form and control elements related to the fields Form footer a place for any items which will appear at the bottom of the form

MS Access Forms

MS Access Forms
A Form can be associated with a Table Must be bound with fields from the source table or query Contain data from correspondent fields, labels or other controls (like command button) or another form called subform Viewing Forms: Open database Click Forms tab to display all available forms in the database Select the form Select Open To view data use Form Navigation Tools. To prevent data Editing, use Locked Property for the Text Boxes Forms can be used for editing data The results of query can also be displayed in form

Sub Forms A Form can have many sub forms Represent 1:N relationships To add a subform to a form Create a form that will be a subform Click on Subform/Subreport button and then click on a form where the subform should appear Specify the source for the subform Specify the fields to link the form and subform Reports present table contents or query results in an easily assimilated format Reports have Design view and Print Preview Report Design View is similar to the Form Design view

MS Access Forms and Reports

Reports Page Header contains data and graphics appearing at the top
of each page Report Header contains the data and graphics appearing at the top of the first report page Detailed section contains data from tables or queries Page Footer contains the data and graphics appearing at the bottom of every page Report Footer contains the data and graphics appearing at the bottom of the last report page Reports can be of following types Columnar reports a single record on a page Tabular reports datasheets: fields from the tables are presented as columns Justified reports combine two previous types of the reports

Creating Reports
With a Wizard Design view: Specify source for the report . The source is one or more tables. A Query can also be specified Select Fields from the Fields List Add labels Used for titles and captions The headers can also be described here The data formatting can also be done Switch the view to see the result.

You might also like