• Aucun résultat trouvé

A Painless Introduction to MS Access Databasing

N/A
N/A
Protected

Academic year: 2022

Partager "A Painless Introduction to MS Access Databasing"

Copied!
44
0
0

Texte intégral

(1)

Lane Medical Library & Knowledge Management Center http://lane.stanford.edu

A Painless Introduction

to MS Access Databasing

Yannick Pouliot, PhD

Bioresearch Informationist [email protected]

Lane Medical Library & Knowledge Management Center

4/20/07

(2)

Preliminaries

 Launch MS Access

 Open Simple1.mdb

 File/Open

 Using the Help  don’t neglect it!

 Exercise: ask the Office Assistant for “select

syntax”

(3)

Lane Medical Library &

Knowledge Management Center http://lane.stanford.edu

3

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

(4)

Resources – MS Access

Available as eBook

Available as eBook

(5)

Lane Medical Library &

Knowledge Management Center http://lane.stanford.edu

5

Resources – Excel/MS Query

In Lane catalog

(6)

Resources – MS Access

Free Online Training Resources

 Using an Access database to store and information (2 min)

http://office.microsoft.com/en-us/assistance/HA011709681033.aspx

 Creating a database from Excel (5 min):

http://office.microsoft.com/en-us/assistance/HA012013211033.aspx

 Creating tables in Access (50 min):

http://office.microsoft.com/training/training.aspx?AssetID=RC061183261033

 Writing queries (50 min): http://office.microsoft.com/training/training.aspx?

AssetID=RC010776611033

(7)

Lane Medical Library &

Knowledge Management Center http://lane.stanford.edu

7

Why Bother with MS

Access?

(8)

Why MS Access?

 More: http://office.microsoft.com/en-

us/access/HA010429181033.aspx

(9)

Lane Medical Library &

Knowledge Management Center http://lane.stanford.edu

9

Definitions,

Definitions…

(10)

Definitions

 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

 Query

 Set of instructions to a database “engine” to retrieve, sort and format returning data.

 E.g., “find me all patients in my database”

 Database engine

 Software application that stores the data and enables querying

(11)

Lane Medical Library &

Knowledge Management Center http://lane.stanford.edu

11

Table and Field Definitions

How It Looks In Access…

(12)

Main Relational Database Engines

 Oracle

 MS Access

 MS SQL Server

 Filemaker

 MS SQL Server

 MySQL

 Postgress

 Sybase

(13)

Lane Medical Library &

Knowledge Management Center http://lane.stanford.edu

13

Understanding Relational

Databases

(14)

Understanding the Relational Principle: A Simple Database

 Every patient gets ONE record in the Patients table

 Every visit gets ONE record in the Visits table

 Rows in different tables can be related one to another using a shared key (identifier  number unique to table)

 There can be multiple visits records for a given patient

 There can be multiple tissue records for a given patient

“join”

(15)

Lane Medical Library &

Knowledge Management Center http://lane.stanford.edu

15

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

(16)

The 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

(17)

Lane Medical Library &

Knowledge Management Center http://lane.stanford.edu

17

Example: The Schema for SRI’s

BioWarehouse System

(18)

Querying MS Access

or any relational database…

(19)

Lane Medical Library &

Knowledge Management Center http://lane.stanford.edu

19

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)

(20)

Introducing The SQL Select Statement

 Good news: This is the only SQL statement

you need to understand for querying

 Exercise: run

SuperSimpleQuery1 in Simple1 database

SELECT LastName, FirstName

FROM Patients

(21)

Lane Medical Library &

Knowledge Management Center http://lane.stanford.edu

21

Basic Syntax of Select Statement

SELECT field_name FROM table

[WHERE condition]

Example:

Select LastName,FirstName From Patients

Where Alive = ‘Y’;

Important: Everything is MS Access is case sensitive

 LastName ≠ lastName

[ ] = elective

(22)

Realistic

Querying With

the MS Access

Query Builder

(23)

Lane Medical Library &

Knowledge Management Center http://lane.stanford.edu

23

A More Complete Description of Select Statement

SELECT [DISTINCT|COUNT] field_list FROM table_list

[WHERE conditions]

[GROUP BY field_list]

[ORDER BY field_list [ASC | DESC] ]

more : http://office.microsoft.com/en-us/access/HP010322651033.aspx?

pid=CH010410171033

Includes examples and descriptions of each

SELECT operator (e.g., “group by”)

(24)

Meaningful Queries in Acces

Exercises - Database: Simple2.mdb

1. Returning ordered records

2. Counting records

 LifetimeNumberFAQs1

 Exercise: how many FAQs per day?

 LifetimeNumberFAQs2

 Demo: creating Pivot Tables

3. Generating averages

 Querying from a query!

4. Change order of columns

5. Change sorting of rows

(25)

Lane Medical Library &

Knowledge Management Center http://lane.stanford.edu

25

Uploading

Data in MS

Access

(26)

Importing Data Into Acces From Access

Important

 Column headers in Excel file must match those of columns in Access target table

 No spaces, weird characters

 Must ensure that data in Excel columns is of correct type (text, number, date)

 Blanks (not empty cells!) are nasty

 Exercise: Loading data via Excel

 File: LoadingData.xls

 Demo: http://office.microsoft.com/en-

(27)

Lane Medical Library &

Knowledge Management Center http://lane.stanford.edu

27

Creating an Access DB from Excel

 One table per Excel worksheet

 Demo: http://office.microsoft.com/en-

us/access/HA012013211033.aspx

(28)

Cool Things You Can Do In Access

 Store entire files in records

 Excel, Word, sounds, pictures anything

(29)

Lane Medical Library &

Knowledge Management Center http://lane.stanford.edu

29

Extras

(30)

Creating Forms Using MS InfoPath

 Really the easiest way to create interfaces to

Access

 10 min of work

 Probably 30 for you 

 More:

http://office.microsoft.com

/en- us/access/HA011199501

(31)

Lane Medical Library &

Knowledge Management Center http://lane.stanford.edu

31

Querying With MS Excel

 MSQuery, an unknown hero

 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

(32)

To 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

(33)

Lane Medical Library &

Knowledge Management Center http://lane.stanford.edu

33

Yannick Pouliot, PhD

[email protected]

(34)

The Nitty-

Gritty Details

(35)

Lane Medical Library &

Knowledge Management Center http://lane.stanford.edu

35

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.

(36)

Step1: 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

(37)

Lane Medical Library &

Knowledge Management Center http://lane.stanford.edu

37

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

(38)

Oracle Driver: Needed to Query Oracle Databases

Installing “client” software will also install driver

Windows: Download 10g Client here

Mac: Download 10g Client here

Free Oracle user account required to download

Must be installed if you are querying

using MS Query or any other query

(39)

Lane Medical Library &

Knowledge Management Center http://lane.stanford.edu

39

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

(40)

Words of Caution

 Easy to build queries that

 Retrieve nonsense

 Never complete, end up completely bogging down the database

 Scotty to Captain Kirk: “Where going in circles, and at warp 6 we’re going mighty fast…”

 Understanding schema is only way to prevent that

 Not always easy…

(41)

Lane Medical Library &

Knowledge Management Center http://lane.stanford.edu

41

Resources – SQL

The Language to Query Relational Databases

 Beginning SQL, Wilton P & Colby JW: E http://jenson.stanford.edu/uhtbin/cgisirsi

/5AGuKeptoD/GREEN/59960102/9#holdings

 Oracle SQL*Plus, Gennick, J.

Beginning MySQL: e-book

http://site.ebrary.com/lib/stanford/Doc?

id=10114227

(42)
(43)

Lane Medical Library &

Knowledge Management Center http://lane.stanford.edu

43

The Relational Principle in Action

 Related records can be found using a shared key

 Example: Patients.ID = Visits.PatientID

(44)

SQL Querying…With What?

Other query browsers exist but are more sophisticated

= more complex

Example: PL/SQL Developer, from Allround Automations

Références

Documents relatifs

myoelectrical activity in health and functional disorders showed low SSB activity in six diarrhoeal patients in whom sigmoid activity was recorded over 10 hours.' The SSBs have

Based on reliable information provided by the database set, the ego vehicle lane position can be defined by computations allocating observations one the extreme lanes (under regular

grunt gallery is pleased to announce the exhibition of Gutter Snipes I by Canadian artist Cal Lane.. Gutter Snipes I is an aluminum-coated steel sewer pipe that is carved away

20 This aligns with recommendations from the American Urological Association and the European Association of Urology but not those from the Canadian Task Force on Preventive

Those include: punctuate porokeratosis, punctuate porokeratotic keratoderma, spiny keratoderma on the palms and soles, spiny keratoderma, palmoplantar filiform hyperkeratosis,

system gathers data from the peer community (here: healthcare providers) and checks it against domain specific knowledge of

When the vehicle is traveling on a lane with lane markings, the camera is supposed to be able to detect one or both border lines of the lane. Map-matching here is to determine which

On the other hand, the impact of reserving a lane with busy traffic is obviously different from that with less traffic. It should be carefully considered selecting roads from the network