Using Structured Query Language (SQL) NCCS Applications –MS Access queries (“show SQL”) –SAS (PROC SQL) –MySQL (the new dataserver) –Visual Foxpro Other.

Slides:



Advertisements
Similar presentations
Haas MFE SAS Workshop Lecture 3:
Advertisements

Relational Algebra, Join and QBE Yong Choi School of Business CSUB, Bakersfield.
Concepts of Database Management Seventh Edition
Concepts of Database Management Sixth Edition
Concepts of Database Management Seventh Edition
Introduction to Structured Query Language (SQL)
The University of Akron Dept of Business Technology Computer Information Systems The Relational Model: Query-By-Example (QBE) 2440: 180 Database Concepts.
Midterm Review Lecture 14b. 14 Lectures So Far 1.Introduction 2.The Relational Model 3.Disks and Files 4.Relational Algebra 5.File Org, Indexes 6.Relational.
Introduction to Structured Query Language (SQL)
Chapter 3: Using SQL Queries to Insert, Update, Delete, and View Data
Structured Query Language Chapter Three (Excerpts) DAVID M. KROENKE’S DATABASE CONCEPTS, 2 nd Edition.
1 DB Implementation: MS Access Queries. 2 Outline Access Queries ► Query Creation ► Sorting & Filtering ► Query Types ► Dynamic Query.
Introduction to Structured Query Language (SQL)
Concepts of Database Management Sixth Edition
Microsoft Access 2010 Chapter 7 Using SQL.
State of Connecticut Core-CT Project Query 4 hrs Updated 1/21/2011.
DAY 21: MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Akhila Kondai October 30, 2013.
From VS C# 2010 Programming, John Allwork 1 VS2010 C# Programming - DB intro 1 Topics – Database Relational - linked tables SQL ADO.NET objects Referencing.
Concepts of Database Management, Fifth Edition
ASP.NET Programming with C# and SQL Server First Edition
Chapter 3 Single-Table Queries
PHP Programming with MySQL Slide 8-1 CHAPTER 8 Working with Databases and MySQL.
Microsoft Access 2010 Chapter 7 Using SQL. Change the font or font size for SQL queries Create SQL queries Include fields in SQL queries Include simple.
Concepts of Database Management Seventh Edition
Chapter 15: Using LINQ to Access Data in C# Programs.
Chapter 7 Advanced SQL Database Systems: Design, Implementation, and Management, Sixth Edition, Rob and Coronel.
HAP 709 – Healthcare Databases SQL Data Manipulation Language (DML) Updated Fall, 2009.
INFO 344 Web Tools And Development CK Wang University of Washington Spring 2014.
Analyzing Data For Effective Decision Making Chapter 3.
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
Relational Databases Database Driven Applications Retrieving Data Changing Data Analysing Data What is a DBMS An application that holds the data manages.
Concepts of Database Management Seventh Edition
Using Special Operators (LIKE and IN)
Concepts of Database Management Seventh Edition
Getting to Know SQL. © Jim Hope 2002 All Rights Reserved Data Manipulation SELECT statement INSERT INTO statement UPDATE statement DELETE statement TRANSFORM.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
Concepts of Database Management Eighth Edition Chapter 3 The Relational Model 2: SQL.
Reports and Queries Chapter 3 – Access text Reports – Page Queries – Page
1 DBS201: Introduction to Structure Query Language (SQL) Lecture 1.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
SQL Jan 20,2014. DBMS Stores data as records, tables etc. Accepts data and stores that data for later use Uses query languages for searching, sorting,
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 (Part II) INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor.
Concepts of Database Management Seventh Edition Chapter 3 The Relational Model 2: SQL.
DAY 21: MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Aliya Farheen October 29,2015.
SqlExam1Review.ppt EXAM - 1. SQL stands for -- Structured Query Language Putting a manual database on a computer ensures? Data is more current Data is.
1 2 Concepts of Database Management, 4 th Edition, Pratt & Adamski Chapter 2 The Relational Model 1: Introduction, QBE, and Relational Algebra.
(SQL - Structured Query Language)
A Guide to SQL, Eighth Edition Chapter Five Multiple-Table Queries.
A Guide to SQL, Eighth Edition Chapter Four Single-Table Queries.
WEEK# 12 Haifa Abulaiha November 02,
Manipulating Data Lesson 3. Objectives Queries The SELECT query to retrieve or extract data from one table, how to retrieve or extract data by using.
7 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel 7.6 Advanced Select Queries SQL provides useful functions that.
There’s a particular style to it… Rob Hatton
MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Sravanthi Lakkimsety Mar 14,2016.
SAS ® 101 Based on Learning SAS by Example: A Programmer’s Guide Chapter 26 By Tasha Chapman, Oregon Health Authority.
 CONACT UC:  Magnific training   
BTM 382 Database Management Chapter 8 Advanced SQL Chitu Okoli Associate Professor in Business Technology Management John Molson School of Business, Concordia.
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.
Concepts of Database Management, Fifth Edition Chapter 3: The Relational Model 2: SQL.
Database Systems: Design, Implementation, and Management Tenth Edition
Database Management  .
Chapter 8 Working with Databases and MySQL
Database systems Lecture 3 – SQL + CRUD
Structured Query Language
Introduction To Structured Query Language (SQL)
Index Note: A bolded number or letter refers to an entire lesson or appendix. A Adding Data Through a View ADD_MONTHS Function 03-22, 03-23,
Contents Preface I Introduction Lesson Objectives I-2
Database Systems: Design, Implementation, and Management Tenth Edition
CS3220 Web and Internet Programming SQL and MySQL
Manipulating Data Lesson 3.
Presentation transcript:

Using Structured Query Language (SQL) NCCS Applications –MS Access queries (“show SQL”) –SAS (PROC SQL) –MySQL (the new dataserver) –Visual Foxpro Other popular databases –Oracle, Microsoft SQL Server

SQL or “Zen and the Art of Working with Data” (Part 1)

Training Goals Understand CONCEPTS and VISUALIZE the data. Learn a few key terms that you can use for searching programming language guides or indexes. “Computer awareness”: Learn to think like a computer (when needed). Improve data problem solving.

Basic Concepts Database – collection of tables Table – rows (records) and columns (also called variables or fields)

Basic Commands SELECT.. FROM.. SELECT * FROM temp INSERT INTO... INSERT INTO temp (ein, name) VALUES (“ ”, “My org.”) UPDATE SET... UPDATE temp SET EIN = “ ”, NAME = “My org.” WHERE NAME = “My Old Org.” DELETE WHERE ein = “ ” CREATE DROP

SELECT CREATE TABLE tempNew AS SELECT ein, name FROM temp ORDER BY ein, name WHERE NAME = “ ” Which fields? Three choices:  * (asterisk)  List fields separated by commas  Create new fields (“firstname || lastname AS fullname”) FROM what source? Sort?... ORDER BY ein, name For which records? WHERE NAME = “ ” Where is the result going?  CREATE TABLE tempNew AS SELECT * FROM temp; (SAS)  CREATE TABLE tempNew SELECT * FROM temp;  SELECT... INTO TABLE tempNew (Foxpro) Summary or Detail Output?

“Calculated Fields”/Expressions Concatenate & manipulate strings: SELECT ein || taxper AS nccskey, LOWER(SUBSTR(name,1,30)) as name2... FROM core99... Create “row” percentages: SELECT p1tcont/p1totrev * 100 as contPct,... Flag problem records: SELECT IIF( p1tcont > p1totrev, 1, 0) as contbad... SELECT SUM( contbad) as bad, COUNT(ein) as count... GROUP BY nteecc

SELECT for Summarizing SELECT state, SUM(p1tcont) as totCont, COUNT( ein) as COUNT FROM temp GROUP BY state GROUP BY vs. ORDER BY Skip the GROUP BY, get a “total total” Summary functions: SUM() COUNT() - May behave differently in different programs. COUNT(*), COUNT(ein), COUNT( p1tcont) AVG() MIN() MAX()

Joining Tables: Sample Data

Inner & Outer Joins Inner = intersection of 2 sets SELECT core92.exps as exp92, core96.exps as exp96 FROM core92, core96 WHERE core92.ein = core96.ein; Outer = union of 2 sets SELECT core92.exps as exp92, core96.exps as exp96 FROM core92 LEFT JOIN core96 ON core92.ein = core96.ein;

Advanced Topics Subqueries: “Organizations in 1999 but NOT in 1998 files?” SELECT * FROM core99 WHERE EIN NOT IN (SELECT ein FROM core98); Dynasets (Access), Views (SAS) vs. Static sets: Data from some Access queries or Views can be edited. Working with LARGE datasets: INDEXing or SORTing dramatically improve performance. Find duplicates: SELECT ein, COUNT(ein) … GROUP BY ein HAVING count > 1;

Creating Tables, Inserting Rows Creating a table: CREATE new (ein C(9), name C(50)) Inserting a row: INSERT INTO new (ein, name) VALUES (core99.ein, core99.name);

Comparison Operators =, >, =, <= MySQL, SAS: name LIKE “%THEAT%” Access: name LIKE “*THEAT*”

ODBC: Open Data Base Connectivity To get there: Control Panel, ODBC or Admin. Tools, ODBC

Access: “SQL View” INSERT INTO vartest ( variable, format, disabled, label, qSubText, sequence, keyfield, display, required, form ) SELECT [Variable Dictionary].Field_name AS variable, IIf(IsNull([NDW_format]),"float0",[ndw_format]) AS format, [Variable Dictionary].NDW_disabled AS disabled, [Variable Dictionary].NDW_label AS LABEL, [Variable Dictionary].Description AS QSUBTEXT, [Variable Dictionary].NDW_sequence AS sequence, [Variable Dictionary].NDW_keyfield AS keyfield, [Variable Dictionary].NDW_display AS display, [Variable Dictionary].NDW_required AS required, "Core90Test" AS form FROM [Variable Dictionary] INNER JOIN (Files INNER JOIN [File/Variable Junction] ON (Files.[File ID] = [File/Variable Junction].[File ID]) AND (Files.[File ID] = [File/Variable Junction].[File ID])) ON [Variable Dictionary].FieldID = [File/Variable Junction].FieldID WHERE (((Files.filename1)="core90c3"));

Resources online documentationwww.mySql.com UI SAS users group intranet: Full SAS manuals are also online (somewhere)