Lane Medical Library &Knowledge Management Center Resources – Excel/MS Query In Lane catalog... Lane Medical Library &Knowledge Management Center Why Bother with MS Access?... Lane Medi
Trang 1Lane Medical Library & Knowledge Management Center http://lane.stanford.edu
Trang 2 Launch MS Access
Open Simple1.mdb
File/Open
Using the Help don’t neglect it!
Exercise: ask the Office Assistant for “select syntax”
Trang 3Lane Medical Library &
Knowledge Management Center
Contents
Familiarization with MS Acces
Understanding a simple database
Basics of SQL querying
Creating a simple database
Loading database via MS Excel
Tools for running SQL queries
Installation (Windows)
Selected databases
Resources & cheat sheet
Trang 4Resources – MS Access
Available as eBook Available as eBook
Trang 5Lane Medical Library &
Knowledge Management Center
Resources – Excel/MS Query
In Lane catalog
Trang 6Resources – MS Access
Free Online Training Resources
Using an Access database to store and information (2 min)
Writing queries (50 min):
http://office.microsoft.com/training/training.aspx?
AssetID=RC010776611033
Trang 7Lane Medical Library &
Knowledge Management Center
Why Bother with MS
Access?
Trang 8Why MS Access?
More: http://office.microsoft.com/en-us/access/HA010429181033.aspx
Trang 9Lane Medical Library &
Knowledge Management Center
Definitions, Definitions…
Trang 10 Database: Collection of tables
Table
Collection of records that share a common fundamental characteristic
E.g., patients and locations can each be stored in their own table
Schema
A view that inter-relates tables to each other
Record
Basic unit of information in a relational table
E.g., 1 record per person
A record is composed of fields
Trang 11Lane Medical Library &
Knowledge Management Center
Table and Field Definitions
How It Looks In Access…
Trang 12Main Relational Database Engines
Trang 13Lane Medical Library &
Knowledge Management Center
Understanding Relational
Databases
Trang 14Understanding the Relational Principle : A
Simple Database
key (identifier number unique to table)
“join”
Trang 15Lane Medical Library &
Knowledge Management Center
The Relational Principle in Action
Related records can be found using a shared key
Shared key = identifier that is:
unique to each table
Can be referenced by another table
Example: Patients ID = Visits PatientID
Trang 16The Database Schema : Your
Roadmap For Querying
The schema describes all tables and all fields
Describes relationships between tables
Crucial in enabling retrievall of desired data
Simple example:
Very important
Must understand schema for accurate querying
Wrong understanding = wrong results
Trang 17Lane Medical Library &
Knowledge Management Center
Example: The Schema for SRI’s
BioWarehouse System
Trang 18Querying MS Access
or any relational database…
Trang 19Lane Medical Library &
Knowledge Management Center
How Relational Databases Are
Queried
Querying = extracting information out of the database
… and into something, e.g., Excel
This is done using the Structured Query Language (SQL)
Trang 20Introducing The SQL Select Statement
Trang 21Lane Medical Library &
Knowledge Management Center
Where Alive = ‘Y’;
Important: Everything is MS Access is case sensitive
LastName ≠ lastName
[ ] = elective
Trang 22Realistic
Querying With
the MS Access
Query Builder
Trang 23Lane Medical Library &
Knowledge Management Center
Includes examples and descriptions of each SELECT operator (e.g.,
“group by”)
Trang 24Meaningful Queries in Acces
Exercises - Database: Simple2.mdb
1 Returning ordered records
Querying from a query!
4 Change order of columns
Change sorting of rows
Trang 25Lane Medical Library &
Knowledge Management Center
Uploading
Data in MS
Access
Trang 26Importing Data Into Acces From
Access
Important
of columns in Access target table
No spaces, weird characters
correct type (text, number, date)
Blanks (not empty cells!) are nasty
File: LoadingData.xls
Demo:
Trang 27http://office.microsoft.com/en-Lane Medical Library &
Knowledge Management Center
Creating an Access DB from Excel
One table per Excel worksheet
Demo: http://office.microsoft.com/en-us/access/HA012013211033.aspx
Trang 28Cool Things You Can Do In Access
Store entire files in records
Excel, Word, sounds, pictures anything
Trang 29Lane Medical Library &
Knowledge Management Center
Extras
Trang 30Creating Forms Using MS InfoPath
Really the easiest way to create
Trang 31Lane Medical Library &
Knowledge Management Center
Querying With MS Excel
Free
Facilitates writing of a SQL query graphical
First, need to find it!
Search for “MSQRY32.EXE” using “Search for Files or
Folders”
Search hidden files and folders
On my disk, it is located in C:\Program Files\Microsoft
Office\OFFICE11
Once you find it, create a shortcut to it and rename it e.g MSQuery
move the shortcut to a desired location
Also needed: creating a data source name
Trang 32To Conclude…
If using Excel is a headache, use MS Access
Access can work very well on its own
reasonably easy to learn/use
Lots of free resources to quickly learn how to use it
MS Access + Excel = dynamite
Trang 33Lane Medical Library &
Knowledge Management Center
Yannick Pouliot, PhD
lanebioresearch@stanford.edu
Trang 34The Nitty- Gritty Details
Trang 35Lane Medical Library &
Knowledge Management Center
How to Query Using MS Query
Steps
1 Make sure you have the requisite driver (next slide)
2. Create a Data Source Name (Windows only)
3 Write your query
4 Get the results back into Excel!
See Lane videorecorded class
Managing Experiment Data Using Excel and Frie nds: Digging Out from Under the Avalanche
for lots more details
Trang 36Step1: Getting Drivers
Essential for SQL Querying
A driver is a piece of software that lets your operating system talk to a
database
Installed drivers visible in ODBC manager
“data connectivity” tool
Each database engine (Oracle, MySQL, etc) requires its own driver
Generally must be installed by user
Drivers are needed by Data Source Name tool and querying programs
Require (simple) installation
Trang 37Lane Medical Library &
Knowledge Management Center
MySQL Driver: Needed to Query
MySQL Databases
Windows: Download MySQL Connector/ODBC 3.51 here
Must be installed for direct querying using e.g Excel
Not necessary if you are using the MySQL Query Browser
Trang 38Oracle Driver: Needed to Query
Oracle Databases
Installing “client” software will also install driver
download
Must be installed if you are querying
using MS Query or any other query
Trang 39Lane Medical Library &
Knowledge Management Center
Step 2: Creating a Data Source Name
A Data Source Name (DSN) tells programs on your PC where and how
to query a database
Populating the fields:
Data Source Name: Unique name of your choice
Description: anything
Server: exactly as given by the database provider
Port number: as specified by database provider
Defaults: MySQL: 3306; Oracle: 1521; MS Access: N/A
Trang 40 Understanding schema is only way to prevent that
Not always easy…
Trang 41Lane Medical Library &
Knowledge Management Center
Resources – SQL
The Language to Query Relational Databases
Beginning SQL, Wilton P & Colby JW : E
http://jenson.stanford.edu/uhtbin/cgisirsi/5AGuKeptoD/GREEN/599601 02/9#holdings
Oracle SQL*Plus, Gennick, J.
Beginning MySQL: e-book http://site.ebrary.com/lib/stanford/Doc?
id=10114227
Trang 43Lane Medical Library &
Knowledge Management Center
The Relational Principle in Action
Related records can be found using a shared key
Example: Patients ID = Visits PatientID