VBA and Databases (see Chapter 14 )



Similar documents
Introduction to Microsoft Access 2003

and what does it have to do with accounting software? connecting people and business

Introduction. Introduction: Database management system. Introduction: DBS concepts & architecture. Introduction: DBS versus File system

Introduction: Database management system

SQL - QUICK GUIDE. Allows users to access data in relational database management systems.

TIM 50 - Business Information Systems

1. INTRODUCTION TO RDBMS

MySQL for Beginners Ed 3

DIPLOMA IN WEBDEVELOPMENT

INTRODUCTION DATABASE MANAGEMENT SYSTEMS

David M. Kroenke and David J. Auer Database Processing: Fundamentals, Design and Implementation

- Suresh Khanal. Microsoft Excel Short Questions and Answers 1

5.5 Copyright 2011 Pearson Education, Inc. publishing as Prentice Hall. Figure 5-2

SQL, PL/SQL FALL Semester 2013

Overview of Database Management Systems

ICAB4136B Use structured query language to create database structures and manipulate data

ACCESS Importing and Exporting Data Files. Information Technology. MS Access 2007 Users Guide. IT Training & Development (818)

CS2Bh: Current Technologies. Introduction to XML and Relational Databases. Introduction to Databases. Why databases? Why not use XML?

Database: SQL, MySQL

Relational Database Basics Review

Microsoft Excel 2007 Mini Skills Overview of Tables

SENDING S WITH MAIL MERGE

INTRODUCTION TO MICROSOFT ACCESS Tables, Queries, Forms & Reports

Search help. More on Office.com: images templates

Connecting to your Database!... 3

ICOM 6005 Database Management Systems Design. Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department Lecture 2 August 23, 2001

Exploring Microsoft Office Access Chapter 2: Relational Databases and Multi-Table Queries

Getting Started Guide SAGE ACCPAC INTELLIGENCE

IENG2004 Industrial Database and Systems Design. Microsoft Access I. What is Microsoft Access? Architecture of Microsoft Access

Introduction to Database Systems

Toad for Data Analysts, Tips n Tricks

ISM 318: Database Systems. Objectives. Database. Dr. Hamid R. Nemati

Creating Reports Crystal Clear

Lesson 07: MS ACCESS - Handout. Introduction to database (30 mins)

Databases and Information Management

Oracle Database 10g Express

Intro to Databases. ACM Webmonkeys 2011

Basic Concepts of Database Systems

An Introduction to Relational Database Management System

Database Management. Technology Briefing. Modern organizations are said to be drowning in data but starving for information p.

PROJECT ON MICROSOFT ACCESS (HOME TAB AND EXTERNAL DATA TAB) SUBMITTED BY: SUBMITTED TO: NAME: ROLL NO: REGN NO: BATCH:

Profesor: M.T.I. Juvencio Mendoza Castelán

Computer Skills: Levels of Proficiency

Demystified CONTENTS Acknowledgments xvii Introduction xix CHAPTER 1 Database Fundamentals CHAPTER 2 Exploring Relational Database Components

Pastel Evolution BIC. Getting Started Guide

Getting Started Guide

Topics. Database Essential Concepts. What s s a Good Database System? Using Database Software. Using Database Software. Types of Database Programs

Databases in Engineering / Lab-1 (MS-Access/SQL)

Financial Data Access with SQL, Excel & VBA

Geodatabase Programming with SQL

A Brief Introduction to MySQL

David M. Kroenke and David J. Auer Database Processing 11 th Edition Fundamentals, Design, and Implementation. Chapter Objectives

Computer Information Systems

Introduction to Microsoft Jet SQL

CSE 530A Database Management Systems. Introduction. Washington University Fall 2013

LearnFromGuru Polish your knowledge

Tracking Database Schema Changes. Guidelines on database versioning using Devart tools

3. Relational Model and Relational Algebra

Creating and Using Databases with Microsoft Access

Database Design and Programming

1 File Processing Systems

Micro Focus Database Connectors

4. The Third Stage In Designing A Database Is When We Analyze Our Tables More Closely And Create A Between Tables

Database Management System Choices. Introduction To Database Systems CSE 373 Spring 2013

SQL Server Integration Services Using Visual Studio 2005

Extracting META information from Interbase/Firebird SQL (INFORMATION_SCHEMA)

Talking to Databases: SQL for Designers

UQC103S1 UFCE Systems Development. uqc103s/ufce PHP-mySQL 1

Foundations of Business Intelligence: Databases and Information Management

Module 9 Ad Hoc Queries

What is a database? COSC 304 Introduction to Database Systems. Database Introduction. Example Problem. Databases in the Real-World

ICADBS504A Integrate database with a website

Tutorial on Relational Database Design

Release: 1. ICADBS412A Build a database

Suite. How to Use GrandMaster Suite. Exporting with ODBC

INTRODUCING ORACLE APPLICATION EXPRESS. Keywords: database, Oracle, web application, forms, reports

Chapter 22 Database: SQL, MySQL,

14 Databases. Source: Foundations of Computer Science Cengage Learning. Objectives After studying this chapter, the student should be able to:

Foundations of Business Intelligence: Databases and Information Management

Chapter 4 Accessing Data

ORACLE USER PRODUCTIVITY KIT USAGE TRACKING ADMINISTRATION & REPORTING RELEASE 3.6 PART NO. E

Chapter 1 - Database Systems

full file at

SQL Server An Overview

Technology in Action. Alan Evans Kendall Martin Mary Anne Poatsy. Eleventh Edition. Copyright 2015 Pearson Education, Inc.

Relational Data Analysis I

Extraction Transformation Loading ETL Get data out of sources and load into the DW

Excel 2003, MS Access 2003, FileMaker Pro 8. Which One Should I Use?

Database Query 1: SQL Basics

Chapter 9 Java and SQL. Wang Yang wyang@njnet.edu.cn

SQL Pass-Through and the ODBC Interface

Vendor: Crystal Decisions Product: Crystal Reports and Crystal Enterprise

Introduction to Computing. Lectured by: Dr. Pham Tran Vu

Database Administration with MySQL

Abstract. For notes detailing the changes in each release, see the MySQL for Excel Release Notes. For legal information, see the Legal Notices.

Access Tutorial 2 Building a Database and Defining Table Relationships

TheEducationEdge. Export Guide

Concepts of Database Management Eighth Edition. Chapter 1 Introduction to Database Management

Transcription:

VBA and Databases (see Chapter 14 ) Kipp Martin February 29, 2012

Lecture Files Files for this module: retailersql.m retailer.accdb

Outline 3 Motivation Modern Database Systems SQL Bringing Data Into MATLAB/Excel

Motivation Motivation: Getting data from external sources! Data that is needed for a model may reside in text files (done). Data that is needed for a model may reside in other worksheets and workbooks (done). Data that is needed for a model may reside in modern relational databases (Access, SQL Server, Oracle, DB2) Data that is needed for a model may reside in XML files (next lecture).

Modern Database Systems Characteristics of a database management system (DBMS): Data Manipulation Language get information in and out of the database. SQL is most important standard System Catalog or Data Dictionary meta database, e.g. a tables listing all the tables, keys, attributes, indicies, etc. Utility programs 1. scheduled backups 2. user account management Report Generation

Modern Database Systems Characteristics of a database management system (DBMS): Data import and export Creation of SQL based procedures and interface to programming language Locking mechanisms Transaction processing must end up completed (committed) or completely undone

Modern Database Systems 7 Modern database systems: Popular Commercial Packages: Oracle, DB2/Informix, SQL Server, Sybase, Ingres Open Source: MySQL, PostgreSQL, InterBase, Firebird, SAP DB Desktop: MS Access is the most popular

Modern Database Systems Key Ideas: Relation or table: a flat file. Think of this as a matrix with rows and columns. A range in an Excel spreadsheet Record: a row in the table Field or attribute: a column in the table Primary Key: a subset of the fields with the property that for a given setting of the key values there is a unique value for all other fields. For example, Social Security number. Every table must have a primary key. Composite or multi-field key: is a key with more than one attribute

Modern Database Systems Key Ideas: Universal Relation: a relation containing all the attributes in the database. This is often called a flat file database. Many databases are simple flat files Relational Database: A database that allows for multiple tables which can be joined together in order to get information SQL: Structured Query Language. A way to get information in and out of a database. SQL is to the database world what HTML is to the Web

Modern Database Systems 10 See retailer.accdb The key for this database is rep e mail and sku num (we have a multi-attribute key).

Modern Database Systems Problems with a flat file database: Redundancy consider the retailer example, we may have hundreds or even thousands of SKUs supplied by the same supplier. Why store the same supplier address thousands of times? Deletion Anomalies if we discontinue all of the SKUs of a particular supplier and delete these records, we lose information about the supplier Insertion Anomalies when we insert a new record we may create inconsistencies Null Values How do we treat null values: leave it blank, insert a zero, or a special character?

Modern Database Systems Big breakthrough was the development of a relational database! A relational database allows multiple users throughout a corporation to easily and directly access all of the data. The concept of a relational database is due to Ted Codd, an IBM research fellow, who wrote the theory paper in 1970. This paper was promptly ignored by IBM. Larry Ellison and his associates (Ed Oates) realized the potential. Ellison was a COBOL programmer who wanted to get rich. He did. Ellison has a U of C connection.

Modern Database Systems 13 Normalized Relational Database:

Modern Database Systems Normalized Relational Database:

15 A one-to-many join: Modern Database Systems

SQL Don Chamberlin and Ray Boyce at IBM developed a prototype of SQL and published their results. This is the Gold Standard for databases. All major commercial databases support SQL.

17 Refer back to the retailer table: SQL Example query: Get the e-mail of everyone supplying part number 577 Here is the SQL for the query: SELECT retailer.rep_e_mail, retailer.sku_num FROM retailer WHERE retailer.sku_num=577

18 The result of the query is SQL rep e mail sku num sne@s55.com 577 tjr@s45.com 577 A slight modification of the previous query is: SELECT retailer.rep_e_mail, retailer.sku_num FROM retailer WHERE retailer.sku_num=577 ORDER BY retailer.rep_e_mail DESC with result: rep e mail sku num tjr@s45.com 577 sne@s55.com 577

SQL 19 The SQL for the query Get the city of everyone supplying red parts is: SELECT retailer.city, retailer.color FROM retailer WHERE retailer.color="red" the result of the query is city Ulvade Honda color red red

SQL 20 Here is the SQL for a join get the cities that supply sku 577 SELECT orders.sku_num, supplier.city FROM orders INNER JOIN supplier ON orders.sup_id = supplier.sup_id WHERE orders.sku_num=577 the result of the query is sku num city 577 Plano 577 Lajitas

SQL Note the key words used in these examples: SELECT: specifies the fields you want FROM: specifies the table you want WHERE: specifies the criterion or criteria you want A few other key words: 1. DISTINCT 2. GROUP BY 3. HAVING 4. ORDER BY 5. AS

SQL Some References: See Section 14.4 of Albright A nice tutorial http://www.w3schools.com/sql/default.asp Test some queries in the tutorial http://www.w3schools.com/sql/sql_tryit.asp

Bringing Data Into MATLAB/Excel Key Idea: In most modern organizations most of the data resides in databases (Oracle, DB2, SQL Server, etc.). We want to bring that data into MATLAB/Excel and do something useful with it. Therefore, MATLAB/Excel must communicate with the database server! In Excel (with VBA) and MATLAB we are going to send SQL querier to a database server and get the results back. How is this done in practice?

Bringing Data Into Excel There are two primary ways for Excel to talk to database servers. Use Web Services Use Microsoft ADO (ActiveX Data Objects) We are going to use Web Services far, far, more generic than ADO! The way we access databases in Excel will be indentical to how we do this in MATLAB. It is best to use open, platform independent, standards.

In Class Exercise - Practice SQL 25

In Class Exercise - Practice SQL 26 Query 1: Get all records in the database Query 1: Get all records and sort in decreasing order by price Query 1: Get all records in the database from 1956 Query 1: Get all records in the database recored by the Velours or Jimmy and The Crestones Query 5: Query the doowop database and using a single SQL command return each unique song title and a count of how many times that title appears in the database. Order the result in descending order by count.