Quick Lesson on Databases Relational databases are key to managing complex data You’ve been using relational databases with “Joins” and “Relates” in ArcGIS.

Slides:



Advertisements
Similar presentations
Advanced SQL Topics Edward Wu.
Advertisements

Tuning: overview Rewrite SQL (Leccotech)Leccotech Create Index Redefine Main memory structures (SGA in Oracle) Change the Block Size Materialized Views,
What is a Database By: Cristian Dubon.
2010/11 : [1]Building Web Applications using MySQL and PHP (W1)MySQL Recap.
The Relational Database Model
Introduction to Structured Query Language (SQL)
XP Chapter 3 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Analyzing Data For Effective Decision Making.
Introduction to Structured Query Language (SQL)
CSE 190: Internet E-Commerce Lecture 10: Data Tier.
Chapter 3: Using SQL Queries to Insert, Update, Delete, and View Data
Introduction to Structured Query Language (SQL)
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 7 Introduction to Structured Query Language (SQL)
Phil Brewster  One of the first steps – identify the proper data types  Decide how data (in columns) should be stored and used.
Introduction To Databases IDIA 618 Fall 2014 Bridget M. Blodgett.
DAY 21: MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Akhila Kondai October 30, 2013.
Attributes & Queries Reading Assignment: Bolstad, Ch. 8 (p )
GIS UPDATE? Lecture 17 Lab 8: Music Festival, Part 2 – Spatial Analysis.
Guide to Oracle10G1 Using SQL Queries to Insert, Update, Delete, and View Data Chapter 3.
Session 5: Working with MySQL iNET Academy Open Source Web Development.
ASP.NET Programming with C# and SQL Server First Edition
LOGO 1 Lab_02: Basic SQL. 2 Outline  Database Tables  SQL Statements  Semicolon after SQL Statements?  SQL DML and DDL  SQL SELECT Statement  SQL.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor Ms. Arwa.
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
DAY 15: ACCESS CHAPTER 2 Larry Reaves October 7,
Database A collection of related data. Database Applications Banking: all transactions Airlines: reservations, schedules Universities: registration, grades.
Introduction to SQL Steve Perry
FIA Forest Inventory Analysis Plots in forests over the US –Coordinates “fuzzed” at 1km –Tree species and characteristics –Resampled every decade FIA database:
Rensselaer Polytechnic Institute CSCI-4380 – Database Systems David Goldschmidt, Ph.D.
Chapter 7 Working with Databases and MySQL PHP Programming with MySQL 2 nd Edition.
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
Structure Query Language SQL. Database Terminology Employee ID 3 3 Last name Small First name Tony 5 5 Smith James
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
M1G Introduction to Database Development 5. Doing more with queries.
Quick Lesson on Databases Relational databases are key to managing complex data You’ve been using relational databases with “Joins” and “Relates” in ArcGIS.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
DAT602 Database Application Development Lecture 3 Review of SQL Language.
5. Simple SQL using Oracle1 Simple SQL using Oracle 5. Working with Tables: Data management and Retrieval 6. Working with Tables: Functions and Grouping.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
Visual Programing SQL Overview Section 1.
Using SQL Connecting, Retrieving Data, Executing SQL Commands, … Svetlin Nakov Technical Trainer Software University
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 (Part II) INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor.
SQL/Lesson 7/Slide 1 of 32 Implementing Indexes Objectives In this lesson, you will learn to: * Create a clustered index * Create a nonclustered index.
Date: 13/03/2015 Training Reference: 2015 GIS_01 Document Reference: 2015GIS_01/PPT/L4 Issue: 2015/L4/1/V1 Addis Ababa, Ethiopia GIS Data Base Management.
Database: SQL, MySQL, LINQ and Java DB © by Pearson Education, Inc. All Rights Reserved.
Distribution of Marks For Second Semester Internal Sessional Evaluation External Evaluation Assignment /Project QuizzesClass Attendance Mid-Term Test Total.
Starting with Oracle SQL Plus. Today in the lab… Connect to SQL Plus – your schema. Set up two tables. Find the tables in the catalog. Insert four rows.
7 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel 7.6 Advanced Select Queries SQL provides useful functions that.
Week 2 Lecture The Relational Database Model Samuel ConnSamuel Conn, Faculty Suggestions for using the Lecture Slides.
LM 5 Introduction to SQL MISM 4135 Instructor: Dr. Lei Li.
MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Sravanthi Lakkimsety Mar 14,2016.
MySQL Tutorial. Databases A database is a container that groups together a series of tables within a single structure Each database can contain 1 or more.
BTM 382 Database Management Chapter 8 Advanced SQL Chitu Okoli Associate Professor in Business Technology Management John Molson School of Business, Concordia.
Introduction to Databases & SQL Ahmet Sacan. What you’ll need Firefox, SQLite plugin Mirdb and Targetscan databases.
Lec-7. The IN Operator The IN operator allows you to specify multiple values in a WHERE clause. SQL IN Syntax SELECT column_name(s) FROM table_name WHERE.
1 Section 1 - Introduction to SQL u SQL is an abbreviation for Structured Query Language. u It is generally pronounced “Sequel” u SQL is a unified language.
LEC-8 SQL. Indexes The CREATE INDEX statement is used to create indexes in tables. Indexes allow the database application to find data fast; without reading.
COM621: Advanced Interactive Web Development Lecture 11 MySQL – Data Manipulation Language.
Chapter 12 Introducing Databases. Objectives What a database is and which databases are typically used with ASP.NET pages What SQL is, how it looks, and.
Quick Lesson on Databases
Web Systems & Technologies
CHAPTER 7 DATABASE ACCESS THROUGH WEB
Prepared by : Moshira M. Ali CS490 Coordinator Arab Open University
Structured Query Language (SQL) William Klingelsmith
CIS16 Application Programming with Visual Basic
Introduction To Structured Query Language (SQL)
Introduction To Structured Query Language (SQL)
Contents Preface I Introduction Lesson Objectives I-2
CS3220 Web and Internet Programming SQL and MySQL
CS3220 Web and Internet Programming SQL and MySQL
Presentation transcript:

Quick Lesson on Databases Relational databases are key to managing complex data You’ve been using relational databases with “Joins” and “Relates” in ArcGIS GeoDatabases are relational databases Structured Query Language (SQL) is the primary language for relational databases You’ve been using SQL statements in ArcGIS to query data

Relational Databases Need to represent data with a complex structure Plot TreeSpecies

Database Tables What you’ve seen in ArcGIS only more flexible Tables are made up of “fields” (columns) and “records” (rows) Queries are used to combine and subset tables into new tables Each table should have a unique, integer, ID, referred to as a primary key –Greatly improves query performance

Field Data Types Numeric –Float or integer –Auto numbered, use for primary keys Dates –YYYY-MM-DD HH:MM:SS.SS – :23:12.34 Text –Specified width –“Variant” width Binary Large Objects (BLOB)

What’s Wrong With This? Tree Query LATLONMEASYEARMEASMONMEASDAYCOMMON_NAMEHT Douglas-fir Douglas-fir Douglas-fir Douglas-fir Douglas-fir Douglas-fir Douglas-fir Douglas-fir Douglas-fir Douglas-fir Douglas-fir Douglas-fir Douglas-fir Douglas-fir Douglas-fir99

Relational Databases Allow us to “relate” tables to: –Reduce the overall amount of data Removes duplicates –Makes updates much easier –Improves search speeds

Entity-Relationship Diagram ERD –Unified Markup Language (UML) Plot TreeSpecies Entities Relationships One to one One to many Many to many Relationship Types

IDLatLonYearMonthDay Plot IDCommon Name 1Douglas-fir 2Ponderosa Pine Species IDPlotIDSpeciesIDHeight …1…… Tree Primary Key Foreign Key

Database Normalization 1.Eliminate duplicate columns from the same table 2.Move fields that have “duplicate” row entries and move them to a related table 3.All field entries should be dependent on the primary key 4.There should be only one primary key in each table

Database Dictionary Defines each of the tables and fields in a database A database forms the basis for data management behind many GIS projects, web sites, and organizations Proper documentation is key to long term success! –Database design (including ERDs) –Database Dictionary

Geospatial Databases Not required to store spatial data! Provide: –Field types for spatial data: point, polyline, polygon, etc. –Spatial operations: union, intersect, etc. –Spatial queries: return records that overlap with a polygon, etc. –Some provide spatial reference control

What we really want What we need from a database: –Distributed, concurrent access (concurrency) –Automatic Backup –Version control –Unlimited amounts of data –Quick data access –Inexpensive –Broad OS Support –File-level copying –GeoSpatial queries, operations, data types

Relational Databases Enterprise-Level –SQL Server –PostgreSQL –MySQL –Oracle –Sybase File-Level –Geodatabase –MS-Access

What we have SQL ServerPostgreSQLESRI Geodatabase MS-Access ConcurrencyYes No Automatic backup Yes No VersioningNo Data Size100s of millions 100,000? PerformanceFast GoodPoor Cost$600 per CPUFree~$10,000 w/ArcGIS ~$400 OSWindowsAnyWindows File-level copyNo Yes Spatial QueriesYes No Spatial data types Yes No Spatial operations Yes No

Structured Query Language (SQL) Comes from the database industry “INSERT”, “DELETE”, and “SELECT” rows in tables Very rich syntax Portions of “SELECT” grammar used heavily in ArcGIS: –Selecting attributes –Raster calculator –Geodatabases

Transaction SQL “SQL” is a subset of T-SQL T-SQL allows full management of a database: –Create & drop: Tables, fields/columns, relationships, indexes, views, etc. –Administrative functions Varies some between databases

Using SQL All Databases have “query editors” that allow us to write, save, edit, and use SQL queries Use programming languages to “write” queries and “fetch” records from the database

SQL: SELECT SELECT Field1, Field2 FROM TableName INNER JOIN TableName2 ON TableName2.FK=TableName.PK WHERE Filter1 AND Filter 2 GROUP BY Field1,Field2 ORDER BY Field1 [DESC], Field2 [DESC] FK=Foreign Key, PK=Primary Key

Selecting Fields SELECT * –Returns all fields as new table SELECT Field1,Field2 SELECT Table1.Field1,Table2.Field1 –Return specified fields SELECT Table1.Field1 AS NewName –Avoids name collisions

Selecting Tables FROM Table1 –Returns contents of one table FROM Table1 INNER JOIN Table2 ON Table2.ForeignKey=Table1.PrimaryKey –Returns records from Table2 that match primary keys in Table1 –Does not return all rows in Table1

Selecting Tables (con’t) FROM Table1 OUTER JOIN Table2 ON Table2.ForeignKey=Table1.PrimaryKey –Returns all matches between Table1 and Table2 and any records in Table1 that don’t match records in Table2 –Missing values are NULL

Filters or “WHERE” clauses SELECT * FROM Table1 WHERE (Field1 Operator Value1) BooleanOperator (Field1 Operator Field2)

Filter Examples WHERE: –ID = 1 –Area < –Area <= –Name = “Crater Lake” (case dependent) –Name LIKE “Crater Lake” (ignores case) Notice: –String values have double quotes –Syntax for strings vary some between databases

SQL Comparisons Equals: = Greater than: > Less than: < Greater than or equal: >= Less than or equal: <= Not equal: <> Like: case independent string comparison with wild cards (%)

Boolean Operators ABA AND BA OR BNOT ANOT B TTTTFF TFFTFT FTFTTF FFFFTT

More Complex Filter Examples WHERE: –Name LIKE “Hawaii” AND Area < –Species LIKE “Ponderosa” AND DBH > 1

ORDER BY SELECT * FROM Table 1 ORDER BY LastName DESC, FirstName DESC Careful with performance on large datasets and string fields

GROUP BY Aggregates data SELECT Species,AVG(Height) FROM Trees GROUP BY Species Only aggregated fields can appear in SELECT list

SQL INSERT INSERT INTO TableName (Field1,Field2) VALUES (Value1,”Value2”) String values must be in quotes –Other values can also be in quotes If the table has an “auto numbered” ID field, it will be added automatically Otherwise, very difficult to set the ID field

SQL DELETE DELETE FROM TableName WHERE ID=Value - Deletes one row DELETE FROM Plot WHERE PlotID=12 - Deletes all rows with PlotID=12 DELETE FROM TableName - Deletes everything in TableName!

Database Performance Default Search Indexed Search Primary Key Search

Indexes Added to a table –Typically for one field Adds overhead to INSERT and DELETEs Important for: –Large tables –Complex queries –Especially text searches!

Maintaining Performance Always use integer, auto numbered primary keys Avoid iterative or hierarchical queries Sometimes code is faster: –Do simple query, load into RAM and sort With REALLY big data, don’t use SQL –NoSQL, accessing data directly, without the use of a relational database package –There are “NoSQL” products in the works Avoid text searches and sorts

Rasters and Databases Don’t put rasters into a database! –Makes it impossible to backup and restore the database –Put a file path to the rasters in the database