Advanced SQL Tribal Data Workshop Joe Nowinski

Similar documents
Sql Server Syllabus. Overview

This course is aimed at those who need to extract information from a relational database system.

Oracle Database 11g: SQL and PL/SQL Fundamentals

Oracle Database: SQL and PL/SQL Fundamentals NEW

Oracle Database: SQL and PL/SQL Fundamentals Ed 2

COPYRIGHTED MATERIAL. Contents. Chapter 1: Introducing T-SQL and Data Management Systems 1. Chapter 2: SQL Server Fundamentals 23.

Oracle Syllabus Course code-r10605 SQL

20761 Querying Data with Transact SQL

Index. Bitmap Heap Scan, 156 Bitmap Index Scan, 156. Rahul Batra 2018 R. Batra, SQL Primer,

1 Writing Basic SQL SELECT Statements 2 Restricting and Sorting Data

Course Outline and Objectives: Database Programming with SQL

Querying Data with Transact-SQL

Course Outline. Querying Data with Transact-SQL Course 20761B: 5 days Instructor Led

Querying Data with Transact-SQL

Querying Data with Transact-SQL

Oracle Database: Introduction to SQL Ed 2

20761B: QUERYING DATA WITH TRANSACT-SQL

Querying Data with Transact-SQL

Querying Data with Transact SQL

DB2 SQL Class Outline

Querying Data with Transact-SQL

Introduction to Computer Science and Business

20761C: Querying Data with Transact-SQL

Duration Level Technology Delivery Method Training Credits. Classroom ILT 5 Days Intermediate SQL Server

5. Single-row function

Oracle Database 10g: Introduction to SQL

Querying Data with Transact-SQL

Teradata SQL Features Overview Version

Greenplum SQL Class Outline

T-SQL Training: T-SQL for SQL Server for Developers

Querying Data with Transact SQL Microsoft Official Curriculum (MOC 20761)

CSC Web Programming. Introduction to SQL

Querying Data with Transact-SQL

Querying Microsoft SQL Server 2014

COURSE OUTLINE: Querying Microsoft SQL Server

20461: Querying Microsoft SQL Server 2014 Databases

SQL Coding Guidelines

AVANTUS TRAINING PTE LTD

MIS NETWORK ADMINISTRATOR PROGRAM

618 Index. BIT data type, 108, 109 BIT_LENGTH, 595f BIT VARYING data type, 108 BLOB data type, 108 Boolean data type, 109

Querying Microsoft SQL Server

After completing this course, participants will be able to:

ASSIGNMENT NO Computer System with Open Source Operating System. 2. Mysql

20461: Querying Microsoft SQL Server

Deccansoft softwareservices-microsoft Silver Learing Partner. SQL Server Syllabus

Oracle Database: SQL and PL/SQL Fundamentals

Querying Microsoft SQL Server

Querying Data with Transact-SQL (761)

MTA Database Administrator Fundamentals Course

Database Systems: Design, Implementation, and Management Tenth Edition. Chapter 7 Introduction to Structured Query Language (SQL)

Course 20461C: Querying Microsoft SQL Server

20461D: Querying Microsoft SQL Server

Microsoft Querying Data with Transact-SQL - Performance Course

Course Modules for MCSA: SQL Server 2016 Database Development Training & Certification Course:

Oracle Database 12c SQL Fundamentals

Review -Chapter 4. Review -Chapter 5

T.Y.B.Sc. Syllabus Under Autonomy Mathematics Applied Component(Paper-I)

"Charting the Course to Your Success!" MOC D Querying Microsoft SQL Server Course Summary

Querying Data with Transact-SQL (20761)

Microsoft Querying Microsoft SQL Server 2014

Chapter 7. Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel

QUERYING MICROSOFT SQL SERVER COURSE OUTLINE. Course: 20461C; Duration: 5 Days; Instructor-led

"Charting the Course... MOC C: Querying Data with Transact-SQL. Course Summary

Oracle Database: Introduction to SQL

The Structured Query Language Get Started

normalization are being violated o Apply the rule of Third Normal Form to resolve a violation in the model

Oracle Developer Track Course Contents. Mr. Sandeep M Shinde. Oracle Application Techno-Functional Consultant

Writing Analytical Queries for Business Intelligence

SQL Interview Questions

COURSE OUTLINE MOC 20461: QUERYING MICROSOFT SQL SERVER 2014

Oracle SQL & PL SQL Course

Aster Data SQL and MapReduce Class Outline

Principles of Data Management

Database Management Systems,

Chapter 3: Introduction to SQL

Microsoft - Querying Microsoft SQL Server 2014 (M20461) (M20461)

INDEX. 1 Basic SQL Statements. 2 Restricting and Sorting Data. 3 Single Row Functions. 4 Displaying data from multiple tables

Part I: Structured Data

Querying Microsoft SQL Server (MOC 20461C)

SQL Server and MSBI Course Content SIDDHARTH PATRA

Database Systems: Design, Implementation, and Management Tenth Edition. Chapter 8 Advanced SQL

MS_20761 Querying Data with Transact-SQL

Language. f SQL. Larry Rockoff COURSE TECHNOLOGY. Kingdom United States. Course Technology PTR. A part ofcenqaqe Learninq

Chapter-14 SQL COMMANDS

Querying Microsoft SQL Server

Oracle Database: Introduction to SQL

Institute of Aga. Network Database LECTURER NIYAZ M. SALIH

CGS 3066: Spring 2017 SQL Reference

A Unit of SequelGate Innovative Technologies Pvt. Ltd. All Training Sessions are Completely Practical & Real-time

Activant Solutions Inc. SQL 2005: Basic Data Manipulation


Relational Database Language

Advanced SQL. Chapter 8 finally!

MCSE Data Management and Analytics. A Success Guide to Prepare- Developing Microsoft SQL Server Databases. edusum.com

Chapter 3: Introduction to SQL

ORACLE TRAINING CURRICULUM. Relational Databases and Relational Database Management Systems

Querying Microsoft SQL Server 2012/2014

Querying Microsoft SQL Server

Oracle Database: Introduction to SQL

Querying Microsoft SQL Server (461)

Transcription:

Advanced SQL 2018 Tribal Data Workshop Joe Nowinski

The Plan Live demo 1:00 PM 3:30 PM Follow along on GoToMeeting Optional practice session 3:45 PM 5:00 PM Laptops available

What is SQL? Structured Query Language Used to query and manipulate data in a database Developed at IBM Originally named SEQUEL

SQL Users SQL is intended as a data base sublanguage for both the professional programmer and the more infrequent database user. (Chamberlin & Boyce, 1974)

SQL Dialects Standard SQL (ANSI) ST-SQL (MS SQL Server) SPL-SQL (Oracle) SPSM-SQL (MySQL)

Basic SQL SELECT FROM JOIN WHERE GROUP BY ORDER BY INSERT INTO UPDATE DELETE

Advanced SQL SQL DML Commands DISTINCT, CASE, GROUP BY, PIVOT, UNION, OVER, MERGE SQL DDL Commands Temp tables, views, stored procedures Automated routines to import & cleanse field data SQL Programmatic Features Variables, loops, and dynamic SQL

DML Commands Data Manipulation Language & functions

DISTINCT Specifies that only unique rows can appear in the result-set How many unique Management Weeks are in the table?

Aliases Used to give a table or a column a temporary name Help make column names more readable Only exists for the duration of the query

CASE Evaluates a list of conditions and returns one result Similar to IF-THEN-ELSE but used within a query

Scalar functions Operate on a single value and then return a single value Conversion functions (CAST, TRY_CAST, ) Date/time functions (GETDATE, DAY, MONTH, YEAR, DATEPART) Mathematical functions (ABS, EXP, LOG, POWER, ROUND, SQRT) String functions (CONCAT, LEN, SUBSTRING, TRIM) https://docs.microsoft.com/en-us/sql/t-sql/functions/functions

Example: SUBSTRING & CAST How far is each PTAGIS site from Bonneville Dam? Problem: RKM is data type VARCHAR(27)

Example: SUBSTRING SUBSTRING extracts a substring from a string 234 308 470 522 522 522 Input column Length Start position

Example: CAST CAST converts an expression from one data type to another 234 308 470 Error Error Error Input column New Data Type

Example: Solution

Aggregate functions Perform a calculation on a set of values and return a single value COUNT, SUM, AVG, MIN, MAX Typically used with the GROUP BY clause of the SELECT statement

QUICK REVIEW: GROUP BY Used to group the result-set by one or more columns SampleData Table Result-set

Example: GROUP BY & COUNT How many of each species were sampled per week?

Example: PIVOT PIVOT rotates a table by turning the unique values from one column into multiple columns in the result-set Can be used with aggregate functions PIVOT Result-set GROUP BY Result-set

Example: PIVOT Distinct values transformed into columns Distinct values to transform defined here

UNION Used to combine the result-set of two of more queries Data type, order, and number of columns must match UNION filters out duplicate rows UNION ALL returns all rows

INTERSECT Returns common records from left and right queries Data type, order, and number of columns must match Filters out duplicate rows Similar to INNER JOIN

EXCEPT Returns records from left query that are not included in right query Data type, order, and number of columns must match Filters out duplicate rows Similar to NOT IN

Example: GROUP BY & UNION GROUP BY ManagementWeek, Species GROUP BY ManagementWeek GROUP BY Species No GROUP BY Clause

GROUPING SETS A GROUP BY clause that uses GROUPING SETS can generate a result set equivalent to that generated by a UNION ALL of multiple simple GROUP BY clauses.

OVER The OVER clause defines the partitioning of rows in a result-set Alternative to GROUP BY

OVER Allows functions to be applied to targeted groups (windows) of rows Three arguments: PARTITION BY divides result-sets into partitions ORDER BY controls ordering of rows within a partition ROWS specifies starting and end points of windows with a partition Video on Window functions & OVER clause

MERGE Performs insert, update, and/or delete operations on a target table based on the results of a join with a source table Target Table Common Field Source Table

MERGE MERGE... ON Source.TagCode = Target.TagCode Matching rows in Source table UPDATE rows in Target table Non-matching rows in Source table INSERT INTO the Target table Non-matching rows in the Target table DELETED from Target table

DDL Commands Data Definition Language

DDL Commands Data Definition Language (DDL) A special group of SQL keywords used to CREATE, ALTER or DROP database objects (e.g., tables, views, stored procedures) Alternative to creating database objects with point & click method Security restricted in some cases*

CREATE Use the CREATE TABLE command to build tables Table Name Column Name Data Type

ALTER Use the ALTER TABLE command to add, alter, or drop columns

DROP Use the DROP TABLE command to delete tables Use IF with the OBJECT_ID function to check if a table exist T-SQL System Object Type Codes

Temporary Tables Act like regular tables but only exist during a session Live in the TempDb (a system database managed by SQL Server) CREATE TABLE #TableName Users do not need CREATE/DROP table permissions

Views A virtual table whose columns and rows are defined by a query Allow DBA to customize how users view data Allow user access to data without granting permissions to the underlying base tables.

Stored Procedures SQL query or routine that is saved inside a database Convenient alternative to writing the same query over and over again Can be executed manually in SSMS, set to run automatically on a schedule, or called by an external application

Creating Stored Procedures CREATE PROCEDURE Template 1. Right click Stored Procedures 2. Select New Stored Procedure 3. Add SQL code to the template 4. Click Execute to save

Executing Stored Procedures Point & Click Or run SQL code 1. Right click stored procedure name 2. Click Execute Stored Procedure 3. Click OK

Example: Automated Import Process File transfer to DB server BULK IMPORT into Temp Table Data cleanse & MERGE into Destination Table

Programmatic Features Variables, Loops, & Dynamic SQL

Variables An object that can hold a single data value of a specific data type DECLARE @Name Data Type Use the SET keyword to initialize

Variables

Variables (Input parameters) 60 50

Variables (output parameters) 4

WHILE LOOP

Dynamic SQL Dynamic SQL is a programming technique that enables you to build SQL statements dynamically at runtime

Example: Dynamic PIVOT table PIVOT tables require hard coding distinct values

Example: Dynamic PIVOT table Dynamic SQL can be used to build a column list at run time Step 1: Select DISTINCT age values into a table Step 2: Use a loop to build a column list string Step 3: Add column list string to PIVOT query Step 4: Check syntax & execute dynamic SQL statement

Example: Dynamic PIVOT table Step 1: Select DISTINCT age values into a table

Example: Dynamic PIVOT table Step 2: Use a loop to build a column list string

Example: Dynamic PIVOT table Step 3: Add column list string to PIVOT query string

Example: Dynamic PIVOT table Step 4: Check syntax & execute dynamic SQL statement

Links Original SEQUEL Whitepaper W3Schools.com Intro to Basic SQL PRAGIM Technologies SQL Video Tutorials Microsoft T-SQL Reference

Links Microsoft T-SQL Reserved Keywords Microsoft BCP Utility Info MS Access SQL vs Standard ANSI SQL