Guofeng Cao CyberInfrastructure and Geospatial Information Laboratory Department of Geography National Center for Supercomputing Applications (NCSA) University.

Slides:



Advertisements
Similar presentations
Basic SQL Introduction Presented by: Madhuri Bhogadi.
Advertisements

Chapter 4 5 6_ SQL SQL Is: Structured Query Language
Sanjay Goel, School of Business, University at Albany, SUNY 1 SQL- Data Definition Language ITM 692 Sanjay Goel.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 4-1 David M. Kroenke Database Processing Chapter 2 Structured Query Language.
Chapter 7: Introduction to SQL
Introduction to Structured Query Language (SQL)
1 © Prentice Hall, 2002 Chapter 7: SQL Modern Database Management 6 th Edition Jeffrey A. Hoffer, Mary B. Prescott, Fred R. McFadden.
1 IS 4420 Database Fundamentals Chapter 7: Introduction to SQL Leon Chen.
Introduction to Structured Query Language (SQL)
Database Management System LICT 3011 Eyad H. Elshami.
1 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management.
DATABASES AND SQL. Introduction Relation: Relation means table(data is arranged in rows and columns) Domain : A domain is a pool of values appearing in.
ASP.NET Programming with C# and SQL Server First Edition
Chapter 6: Introduction to SQL
Shaowen Wang CyberInfrastructure and Geospatial Information Laboratory (CIGI) Department of Geography and National Center for Supercomputing Applications.
Database System SQL November 1st, 2009 Software Park, Bangkok Thailand Pree Thiengburanathum College of Arts and Media Chiang Mai University.
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
1 Chapter 7 Introduction to SQL. 2 Objectives Definition of terms Interpret history and role of SQL Define a database using SQL data definition language.
© 2007 by Prentice Hall (Hoffer, Prescott & McFadden) 1 Introduction to SQL.
CHAPTER 6: INTRODUCTION TO SQL © 2013 Pearson Education, Inc. Publishing as Prentice Hall 1 Modern Database Management 11 th Edition Jeffrey A. Hoffer,
© 2009 Pearson Education, Inc. Publishing as Prentice Hall 1 UNIT 6: Chapter 7: Introduction to SQL Modern Database Management 9 th Edition Jeffrey A.
Chapter 7 SQL HUANG XUEHUA. SQL SQL server2005 introduction Install components  management studio.
© 2011 Pearson Education, Inc. Publishing as Prentice Hall 1 Chapter 6: Introduction to SQL Modern Database Management 10 th Edition Jeffrey A. Hoffer,
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
© 2007 by Prentice Hall 1 Chapter 7: Introduction to SQL Modern Database Management 8 th Edition Jeffrey A. Hoffer, Mary B. Prescott, Fred R. McFadden.
Structure Query Language SQL. Database Terminology Employee ID 3 3 Last name Small First name Tony 5 5 Smith James
SQL SQL Server : Overview SQL : Overview Types of SQL Database : Creation Tables : Creation & Manipulation Data : Creation & Manipulation Data : Retrieving.
1 SQL Tarek El-Shishtawy Professor Ass. Of Computer Engineering.
Dr. Chen, Data Base Management Chapter 6: Introduction to SQL Jason C. H. Chen, Ph.D. Professor of MIS School of Business Administration Gonzaga University.
SQL FUNDAMENTALS SQL ( Structured Query Language )
Chapter 6 © 2013 Pearson Education, Inc. Publishing as Prentice Hall Chapter 6: Introduction to SQL Modern Database Management 11 th Edition Jeffrey A.
CHAPTER 6: INTRODUCTION TO SQL Copyright © 2014 Pearson Education, Inc. 1 Essentials of Database Management Jeffrey A. Hoffer, Heikki Topi, V. Ramesh.
BIS Database Systems School of Management, Business Information Systems, Assumption University A.Thanop Somprasong Chapter # 7 Introduction to Structured.
Topic 1: Introduction to SQL. SQL stands for Structured Query Language. SQL is a standard computer language for accessing and manipulating databases SQL.
Lec 3- B Database Integrity 1. Overview Define a database using SQL data definition language Work with Views Write single table queries Establish referential.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
© 2005 by Prentice Hall 1 Chapter 7: Introduction to SQL Modern Database Management 7 th Edition Jeffrey A. Hoffer, Mary B. Prescott, Fred R. McFadden.
Chapter 7: Introduction to SQL
SQL Fundamentals  SQL: Structured Query Language is a simple and powerful language used to create, access, and manipulate data and structure in the database.
Advanced Database CS-426 Week 1 - Introduction. Database Management System DBMS contains information about a particular enterprise Collection of interrelated.
© 2011 Pearson Education 1 Chapter 6: Basic SQL Modern Database Management 10 th Edition, International Edition Jeffrey A. Hoffer, V. Ramesh, Heikki Topi.
Prince Sultan University Dept. of Computer & Information Sciences CS 340 Introduction to Database Systems.
Visual Programing SQL Overview Section 1.
Guofeng Cao CyberInfrastructure and Geospatial Information Laboratory Department of Geography National Center for Supercomputing Applications (NCSA) University.
SQL Overview Structured Query Language
1 CS 430 Database Theory Winter 2005 Lecture 11: SQL DDL.
1 © Prentice Hall, 2002 Chapter 7: SQL Modern Database Management 6 th Edition Jeffrey A. Hoffer, Mary B. Prescott, Fred R. McFadden.
ECMM6018 Enterprise Networking For Electronic Commerce Tutorial 6 CGI/Perl and databases.
SQL Introduction to database and SQL. Chapter 1: Databases and Database Users 6 Introduction to Databases Databases touch all aspects of our lives. Examples:
CS263 Information Modeling Course tutor: Tony Browne Some diagrams in these notes are small when printed 6.
CSC314 DAY 8 Introduction to SQL 1. Chapter 6 © 2013 Pearson Education, Inc. Publishing as Prentice Hall SQL OVERVIEW  Structured Query Language  The.
Lecture # 24 Introduction to SQL Muhammad Emran Database Systems.
LM 5 Introduction to SQL MISM 4135 Instructor: Dr. Lei Li.
1 Database Fundamentals Introduction to SQL. 2 SQL Overview Structured Query Language The standard for relational database management systems (RDBMS)
Copyright © 2016 Pearson Education, Inc. Modern Database Management 12 th Edition Jeff Hoffer, Ramesh Venkataraman, Heikki Topi CHAPTER 6: INTRODUCTION.
© 2009 Pearson Education, Inc. Publishing as Prentice Hall 1 Lecture 7: Introduction to SQL Modern Database Management 9 th Edition Jeffrey A. Hoffer,
Copyright © 2016 Pearson Education, Inc. Modern Database Management 12 th Edition Jeff Hoffer, Ramesh Venkataraman, Heikki Topi CHAPTER 6: INTRODUCTION.
Physical Model Lecture 11. Physical Data Model The last step is the physical design phase, In this phase data is – Store – Organized and – Access.
CHAPTER 6: INTRODUCTION TO SQL © 2013 Pearson Education, Inc. Publishing as Prentice Hall 1 Modern Database Management 11 th Edition Jeffrey A. Hoffer,
SQL SQL Ayshah I. Almugahwi Maryam J. Alkhalifa
SQL Query Getting to the data ……..
Chapter 5 Introduction to SQL.
Principles of GIS Fundamental database concepts – II Shaowen Wang
Introduction to Structured Query Language(SQL)
CHAPTER 6: INTRODUCTION TO SQL
Database systems Lecture 3 – SQL + CRUD
SQL .. An overview lecture3.
Session - 6 Sequence - 1 SQL: The Structured Query Language:
Structured Query Language Path from Unorganized to Organized….
SQL (Structured Query Language)
Presentation transcript:

Guofeng Cao CyberInfrastructure and Geospatial Information Laboratory Department of Geography National Center for Supercomputing Applications (NCSA) University of Illinois at Urbana-Champaign Geog 480: Principles of GIS

Introduction to SQL

3 SQL Overview Structured Query Language The standard for relational database management systems (RDBMS) SQL-92 and SQL-99 Standards – Purpose: o Specify syntax/semantics for data definition and manipulation o Define data structures o Enable portability o Specify minimal (level 1) and complete (level 2) standards o Allow for later growth/enhancement to standard

4 SQL Environment Catalog o A set of schemas that constitute the description of a database Schema o The structure that contains descriptions of objects created by a user (base tables, views, constraints) Data Definition Language (DDL) o Commands that define a database, including creating, altering, and dropping tables and establishing constraints Data Manipulation Language (DML) o Commands that maintain and query a database Data Control Language (DCL) o Commands that control a database, including administering privileges and committing data

5

6 SQL Data types String types o CHAR(n) – fixed-length character data, n characters long Maximum length = 2000 bytes o VARCHAR(n) – variable length character data, maximum 4000 bytes Numeric types o NUMBER(p,q) – general purpose numeric data type o INTEGER(p) – signed integer, p digits wide o FLOAT(p) – floating point in scientific notation with p binary digits precision Binary Large Objects(BLOB) o Byte Array Geometry types o Box2d, box3d, point, linestring, polygon Date/time type o DATE – fixed-length date/time in dd-mm-yy form

Hands-on keyItemcount keyItemprice

Connecting to Geog480 server

Connecting to Database psql -U username -d database_name o username = geog480 o database_name = tutorial o Enter passwd when prompted (same as username) Postgres Commands o \l List all accessible databases o \dt List all the tables in current DB o \? Help o \q Quite

Table Creation SQL CREATE TABLE Syntax o CREATE TABLE table_name ( column_name1 data_type, column_name2 data_type, column_name3 data_type,.... ) Table Creation Example: o create table count (key int, item varchar(20),count int); o create table price (key int, item varchar(20),price float); Copy from a CSV file (postgres specific) o \COPY count FROM ‘/srv/cigi/code/test.csv' with CSV HEADER

Table Insertion SQL CREATE TABLE Syntax o INSERT INTO table_name VALUES (value1, value2, value3,...) Insertion Example: o insert into count values(1, ‘item0', 100); o insert into count values(2, ‘item1', 101); o insert into count values(3, ‘item2, 102); Copy from a CSV file (postgres specific) o \COPY count FROM ‘/srv/cigi/code/test.csv' with CSV HEADER

Select Table Syntax Used for queries on single or multiple tables Clauses of the SELECT statement: (Sequence!!) o SELECT List the columns (and expressions) that should be returned from the query o FROM Indicate the table(s) or view(s) from which data will be obtained o WHERE Indicate the conditions under which a row will be included in the result o GROUP BY Indicate categorization of results o HAVING Indicate the conditions under which a category (group) will be included o ORDER BY Sorts the result according to specified criteria

Select Table Examples List contents of table o select * from count; o select * from count where item =‘item1'; o Select * from count order by key asc; o select key, count from count limit 5; Counting o select count(*) from count; o select count(*) from count where item like '%1'; Max/Min/Avg o select max(count) from count; o select avg(count) from count where item like '%1%';

Update Tables SQL UPDATE Syntax o UPDATE table_name SET column1=value, column2=value2,... WHERE some_column=some_value Update table Examples: o update count set item =‘item1' where key =1; o update count set count =105 where key=1; Delete Rows o delete from count where key=1;

Join Tables SQL JOIN Syntax o SELECT column_name(s) FROM table_name1 JOIN table_name2 ON table_name1.column_name=table_name2.column_name Example: Join o select count.key, count.item, count.count, price.price from count join price on count.item = price.item;

Using and Defining Views Views provide users controlled access to tables Base Table–table containing the raw data Concepts of View o A “virtual table” created dynamically upon request by a user o No data actually stored; instead data from base table made available to user o Based on SQL SELECT statement on base tables or other views

Create View SQL Syntax o CREATE VIEW view_name AS SELECT column_name(s) FROM table_name WHERE condition Example: Create view: o Create view stock as select count.key, count.item, count.count, price.price from count join price on count.item = price.item;

View Operations Very similar to table operations Multiply two columns o Select count*price as value from stock Drop view o Drop view stock

End of this topic