Data Query
description
Transcript of Data Query
![Page 1: Data Query](https://reader035.fdocuments.us/reader035/viewer/2022062723/56814027550346895dab8710/html5/thumbnails/1.jpg)
Center for Environmental Studies
Arizona State University
Central Arizona PhoenixLTER
Data Query
Peter McCartney
RDIFS Training WorkshopSevilleta LTER
October 28-30, 2002
![Page 2: Data Query](https://reader035.fdocuments.us/reader035/viewer/2022062723/56814027550346895dab8710/html5/thumbnails/2.jpg)
Center for Environmental Studies
Arizona State University
Central Arizona PhoenixLTER
Goals
• Retrieve data from storage• Join tables as needed to produce
matrix output (denormalize)• Transform data to meet analytic
needs– Filter, aggregate, select
![Page 3: Data Query](https://reader035.fdocuments.us/reader035/viewer/2022062723/56814027550346895dab8710/html5/thumbnails/3.jpg)
Center for Environmental Studies
Arizona State University
Central Arizona PhoenixLTER
Structured Query Language
• Universal syntax for querying relational datbases.
• Provides means for specifying– Attributes required– The source tables and how to join
them– Criteria for limiting the result
(filtering)– Instructions for ordering the result set
![Page 4: Data Query](https://reader035.fdocuments.us/reader035/viewer/2022062723/56814027550346895dab8710/html5/thumbnails/4.jpg)
Center for Environmental Studies
Arizona State University
Central Arizona PhoenixLTER
A Simple SQL QuerySELECT personnel.first_name,
personnel.last_name, personnel.country_code
FROM personnelWHERE personnel.country_code="usa“
![Page 5: Data Query](https://reader035.fdocuments.us/reader035/viewer/2022062723/56814027550346895dab8710/html5/thumbnails/5.jpg)
Center for Environmental Studies
Arizona State University
Central Arizona PhoenixLTER
A Slightly More Complex Query
SELECT personnel.first_name, personnel.last_name, country.country_name, interests.interest_area
FROM country INNER JOIN (personnel INNER JOIN interests ON personnel.person_ID = interests.person_ID) ON country.country_code = personnel.country_code
WHERE (((personnel.country_code)="usa"))
![Page 6: Data Query](https://reader035.fdocuments.us/reader035/viewer/2022062723/56814027550346895dab8710/html5/thumbnails/6.jpg)
Center for Environmental Studies
Arizona State University
Central Arizona PhoenixLTER
Result
![Page 7: Data Query](https://reader035.fdocuments.us/reader035/viewer/2022062723/56814027550346895dab8710/html5/thumbnails/7.jpg)
Center for Environmental Studies
Arizona State University
Central Arizona PhoenixLTER
Views
• Views are query statements that are stored in the database.
• Views return a matrix and may be treated as if they were another table (you can use a view in a query)
• Only the query statement is stored; the result set is reproduced each time you call the view
• Views let you hide much of the complicated table joins from your users
![Page 8: Data Query](https://reader035.fdocuments.us/reader035/viewer/2022062723/56814027550346895dab8710/html5/thumbnails/8.jpg)
Center for Environmental Studies
Arizona State University
Central Arizona PhoenixLTER
![Page 9: Data Query](https://reader035.fdocuments.us/reader035/viewer/2022062723/56814027550346895dab8710/html5/thumbnails/9.jpg)
Center for Environmental Studies
Arizona State University
Central Arizona PhoenixLTER
Query a View
SELECT myFirstView.*FROM myFirstViewWHERE
(((myFirstView.interest_area)="data management"));
![Page 10: Data Query](https://reader035.fdocuments.us/reader035/viewer/2022062723/56814027550346895dab8710/html5/thumbnails/10.jpg)
Center for Environmental Studies
Arizona State University
Central Arizona PhoenixLTER
Querying Remote Databases
• The beauty of relational databases is that you can use a variety of client applications to query them.
• Your users do NOT need to learn Access in order to use your database.
![Page 11: Data Query](https://reader035.fdocuments.us/reader035/viewer/2022062723/56814027550346895dab8710/html5/thumbnails/11.jpg)
Center for Environmental Studies
Arizona State University
Central Arizona PhoenixLTER
Accessing Databases
• Native protocol– Every database has its own native
protocol. Applications must be written to this.
• Open Data Base Connectivity– Windows, Unix, Mac
• Java Data Base Connectivity– Cross platform– Designed for Java Language
![Page 12: Data Query](https://reader035.fdocuments.us/reader035/viewer/2022062723/56814027550346895dab8710/html5/thumbnails/12.jpg)
Center for Environmental Studies
Arizona State University
Central Arizona PhoenixLTER
A Typical Client Server Connection
Database(Access)
Application(Excel)
ConnectionLayers(ODBC)
NativeSyntax
StandardSQL
•Connectivity layer translates applications requests into database‘s native syntax.
![Page 13: Data Query](https://reader035.fdocuments.us/reader035/viewer/2022062723/56814027550346895dab8710/html5/thumbnails/13.jpg)
Center for Environmental Studies
Arizona State University
Central Arizona PhoenixLTER
Define an ODBC Source
![Page 14: Data Query](https://reader035.fdocuments.us/reader035/viewer/2022062723/56814027550346895dab8710/html5/thumbnails/14.jpg)
Center for Environmental Studies
Arizona State University
Central Arizona PhoenixLTER
Query
• Once an odbc source is defined, you may access it from any application that supports ODBC
• Excel, SPSS, ArcView, MapInfo, Active Server Pages
• Range of capabilities and user friendly features will vary
![Page 15: Data Query](https://reader035.fdocuments.us/reader035/viewer/2022062723/56814027550346895dab8710/html5/thumbnails/15.jpg)
Center for Environmental Studies
Arizona State University
Central Arizona PhoenixLTER
![Page 16: Data Query](https://reader035.fdocuments.us/reader035/viewer/2022062723/56814027550346895dab8710/html5/thumbnails/16.jpg)
Center for Environmental Studies
Arizona State University
Central Arizona PhoenixLTER
![Page 17: Data Query](https://reader035.fdocuments.us/reader035/viewer/2022062723/56814027550346895dab8710/html5/thumbnails/17.jpg)
Center for Environmental Studies
Arizona State University
Central Arizona PhoenixLTER
![Page 18: Data Query](https://reader035.fdocuments.us/reader035/viewer/2022062723/56814027550346895dab8710/html5/thumbnails/18.jpg)
Center for Environmental Studies
Arizona State University
Central Arizona PhoenixLTER
![Page 19: Data Query](https://reader035.fdocuments.us/reader035/viewer/2022062723/56814027550346895dab8710/html5/thumbnails/19.jpg)
Center for Environmental Studies
Arizona State University
Central Arizona PhoenixLTER
![Page 20: Data Query](https://reader035.fdocuments.us/reader035/viewer/2022062723/56814027550346895dab8710/html5/thumbnails/20.jpg)
Center for Environmental Studies
Arizona State University
Central Arizona PhoenixLTER
Query from Arc View
![Page 21: Data Query](https://reader035.fdocuments.us/reader035/viewer/2022062723/56814027550346895dab8710/html5/thumbnails/21.jpg)
Center for Environmental Studies
Arizona State University
Central Arizona PhoenixLTER
![Page 22: Data Query](https://reader035.fdocuments.us/reader035/viewer/2022062723/56814027550346895dab8710/html5/thumbnails/22.jpg)
Center for Environmental Studies
Arizona State University
Central Arizona PhoenixLTER
![Page 23: Data Query](https://reader035.fdocuments.us/reader035/viewer/2022062723/56814027550346895dab8710/html5/thumbnails/23.jpg)
Center for Environmental Studies
Arizona State University
Central Arizona PhoenixLTER
![Page 24: Data Query](https://reader035.fdocuments.us/reader035/viewer/2022062723/56814027550346895dab8710/html5/thumbnails/24.jpg)
Center for Environmental Studies
Arizona State University
Central Arizona PhoenixLTER
Programming the Web
• Client side– ECMCA languages – Javascript– Code executed by client browser. All data
must be transferred to browser
• Server side– Template “page” scripting– CGI programs
![Page 25: Data Query](https://reader035.fdocuments.us/reader035/viewer/2022062723/56814027550346895dab8710/html5/thumbnails/25.jpg)
Center for Environmental Studies
Arizona State University
Central Arizona PhoenixLTER
Web Query
• HTTPD/CGI programs– External program receives form input,
generates entire page to be returned.– Server side Java
• Server scripting– Permits embedding script within html pages– Html code is returned as is, script code is
executed by script engine prior to page being returned.
– Active Server Pages (MS IIS)– Java Server Pages ( Apache tomcat, BEA
WebLogic, IBM WebSphere, Allaire Jrun
![Page 26: Data Query](https://reader035.fdocuments.us/reader035/viewer/2022062723/56814027550346895dab8710/html5/thumbnails/26.jpg)
Center for Environmental Studies
Arizona State University
Central Arizona PhoenixLTER
Three-tiered Query using ASP
• Declare a connection object and at least one recordset object.
• Open the connection to your ODBC source
• Parse the form request parameters • Build an sql query• Execute the query putting the result in
your recordset• Access the data in your recordset and
write html output to display the data in the page
![Page 27: Data Query](https://reader035.fdocuments.us/reader035/viewer/2022062723/56814027550346895dab8710/html5/thumbnails/27.jpg)
Center for Environmental Studies
Arizona State University
Central Arizona PhoenixLTER
![Page 28: Data Query](https://reader035.fdocuments.us/reader035/viewer/2022062723/56814027550346895dab8710/html5/thumbnails/28.jpg)
Center for Environmental Studies
Arizona State University
Central Arizona PhoenixLTER
![Page 29: Data Query](https://reader035.fdocuments.us/reader035/viewer/2022062723/56814027550346895dab8710/html5/thumbnails/29.jpg)
Center for Environmental Studies
Arizona State University
Central Arizona PhoenixLTER
![Page 30: Data Query](https://reader035.fdocuments.us/reader035/viewer/2022062723/56814027550346895dab8710/html5/thumbnails/30.jpg)
Center for Environmental Studies
Arizona State University
Central Arizona PhoenixLTER
![Page 31: Data Query](https://reader035.fdocuments.us/reader035/viewer/2022062723/56814027550346895dab8710/html5/thumbnails/31.jpg)
Center for Environmental Studies
Arizona State University
Central Arizona PhoenixLTER
![Page 32: Data Query](https://reader035.fdocuments.us/reader035/viewer/2022062723/56814027550346895dab8710/html5/thumbnails/32.jpg)
Central Arizona PhoenixLTER
Center for Environmental Studies
Arizona State University
Lab Assignment
• Add some data to your database• Create some views and store them
in your database– (or use the samples at: \\alamillo\
inetpub\wwwroot\dbweb)• Create an ODBC data source• Query your data from Access• Create an asp page to display
some data following templates:• http://alamillo/dbweb