SlideShare une entreprise Scribd logo
1  sur  25
Télécharger pour lire hors ligne
Quick Intro SQL
it’s SEA QUELL
What is SQL
SQL stands for
Structured
Query
Language
● It is used to access, manipulate and
process data in databases.
What is a database?
A database is a place that stores data, derived
information and process logic.
Common Forms:
● RDBMS - Relational Database Management
System
● NoSQL - a grab bag of multiple systems to
store data
Parts of a RDBMS
● Database / Catalog
● Schema
● Table/ Indices
● View
● Row / Record
● Field / Column
● Stored Procedures/ Functions
Column / Field
A column (or field) is a single piece of data, that
has a defined type and a set purpose
● Text
● Number
● more complex types depend on the RDBMS
Record / Row
A record is a collection of fields grouped
together to provide context to the data
contained
Table / Indices
A table is a collection of records which set
operations can be applied to
So what?
Why is this useful, a database provides a means
to represent real world models and hence
understand through analysis more about the
system modelled
Data Modelling 101
What to model?
● Groceries
● Contact list
● Calendar
You choose :)
What were those join-ey
things
● They can relate tables to each other
● Provide links to information for context
● Minimize storage
Database Forms
First Normal Form
● Eliminate repeating groups in individual
tables.
● Create a separate table for each set of related
data.
● Identify each set of related data with a
primary key.
Database Forms
Second Normal Form
● Create separate tables for sets of values that
apply to multiple records.
● Relate these tables with a foreign key.
Database Forms
Third Normal Form
● Eliminate fields that do not depend on the
key
So how do I get data?
SELECT statment
● Allows you to SELECT data FROM several
tables WHERE certain constraints exist, and
GROUP BY certain fields, it can be ORDER
BY other fields
SELECT
SELECT
employeeName,
startDate,
FROM
employees
WHERE startDate => GETDATE()-7
JOINS
There are various join types in SQL
INNER
LEFT OUTER
LEFT OUTER …. ON t2.field IS NULL
FULL OUTER
Joins...
SELECT …
FROM employee e
INNER JOIN jobtitle j
ON e.jobId = j.jobId
Nested Tables
SELECT …
FROM (
SELECT …
FROM employee
) subTable
More Complexity...
Depending on the platform we have function
that can help process, manipulate and pivot
data
CASE statements
CASE
WHEN x
THEN y
ELSE z
END AS simpleCase
Common Table Expressions...
WITH tableDef(fieldlist)
AS (
… complex query
)
SELECT ….
Recursive CTE...
WITH empTree AS (
SELECT …, 0 AS level
FROM employee
UNION ALL
SELECT …, level + 1 AS level
FROM employee INNER JOIN empTree ON ...
PIVOT and UNPIVOT
SELECT 'AverageCost' AS Cost_Sorted_By_Production_Days,
[0], [1], [2], [3], [4]
FROM
(SELECT DaysToManufacture, StandardCost
FROM Production.Product) AS SourceTable
PIVOT
(
AVG(StandardCost)
FOR DaysToManufacture IN ([0], [1], [2], [3], [4])
) AS PivotTable;
LAG
SELECT BusinessEntityID,
YEAR(QuotaDate) AS SalesYear,
SalesQuota AS CurrentQuota,
LAG(SalesQuota, 1,0)
OVER (ORDER BY YEAR(QuotaDate)) AS PreviousQuota
FROM Sales.SalesPersonQuotaHistory
WHERE BusinessEntityID = 275 and YEAR(QuotaDate) IN
('2005','2006');
Designing complex SQL
Diagram the flow
Model the output
Doodle :)

Contenu connexe

Tendances

Tendances (20)

Sql introduction
Sql introductionSql introduction
Sql introduction
 
Chapter 4 organizing & manipulating the data in database
Chapter 4 organizing & manipulating the data in databaseChapter 4 organizing & manipulating the data in database
Chapter 4 organizing & manipulating the data in database
 
oracle tables
oracle tablesoracle tables
oracle tables
 
Data struters
Data strutersData struters
Data struters
 
SAP ABAP data dictionary
SAP ABAP data dictionarySAP ABAP data dictionary
SAP ABAP data dictionary
 
Data structures
Data structuresData structures
Data structures
 
Introduction to Database Concepts
Introduction to Database ConceptsIntroduction to Database Concepts
Introduction to Database Concepts
 
Relational data model
Relational data modelRelational data model
Relational data model
 
Data structures and Alogarithims
Data structures and AlogarithimsData structures and Alogarithims
Data structures and Alogarithims
 
Data Structure # vpmp polytechnic
Data Structure # vpmp polytechnicData Structure # vpmp polytechnic
Data Structure # vpmp polytechnic
 
Lecture 1 data structures and algorithms
Lecture 1 data structures and algorithmsLecture 1 data structures and algorithms
Lecture 1 data structures and algorithms
 
Intro databases (Table, Record, Field)
Intro databases (Table, Record, Field)Intro databases (Table, Record, Field)
Intro databases (Table, Record, Field)
 
Importing data in Oasis Montaj
Importing data in Oasis MontajImporting data in Oasis Montaj
Importing data in Oasis Montaj
 
Abap data dictionary
Abap data dictionaryAbap data dictionary
Abap data dictionary
 
Database - R.D.Sivakumar
Database - R.D.SivakumarDatabase - R.D.Sivakumar
Database - R.D.Sivakumar
 
Data structure
Data structureData structure
Data structure
 
Data structure
Data structureData structure
Data structure
 
Ppt Lesson 13
Ppt Lesson 13Ppt Lesson 13
Ppt Lesson 13
 
Lecture1 data structure(introduction)
Lecture1 data structure(introduction)Lecture1 data structure(introduction)
Lecture1 data structure(introduction)
 
MS Access Intro
MS Access IntroMS Access Intro
MS Access Intro
 

En vedette

Database Systems - Introduction to SQL (Chapter 3/1)
Database Systems - Introduction to SQL (Chapter 3/1)Database Systems - Introduction to SQL (Chapter 3/1)
Database Systems - Introduction to SQL (Chapter 3/1)Vidyasagar Mundroy
 
El 13 de diciembre
El 13 de diciembreEl 13 de diciembre
El 13 de diciembrelroczey
 
El 22 de febrero
El 22 de febreroEl 22 de febrero
El 22 de febrerolroczey
 
El 6 de enero
El 6 de eneroEl 6 de enero
El 6 de enerolroczey
 
El 23 de febrero
El 23 de febreroEl 23 de febrero
El 23 de febrerolroczey
 
El 2 de enero
El 2 de eneroEl 2 de enero
El 2 de enerolroczey
 
El 3 de enero
El 3 de eneroEl 3 de enero
El 3 de enerolroczey
 
El 10 de febrero
El 10 de febrero El 10 de febrero
El 10 de febrero lroczey
 
El 14 de febrero
El 14 de febreroEl 14 de febrero
El 14 de febrerolroczey
 
IGPS I Assignment 4: Overarching Presentation
IGPS I Assignment 4: Overarching PresentationIGPS I Assignment 4: Overarching Presentation
IGPS I Assignment 4: Overarching Presentationze1337
 
El nueve de marzo
El nueve de marzoEl nueve de marzo
El nueve de marzolroczey
 
El 19 de diciembre
El 19 de diciembreEl 19 de diciembre
El 19 de diciembrelroczey
 
El 11 de enero
El 11 de eneroEl 11 de enero
El 11 de enerolroczey
 
Virtual child (infant & toddler)
Virtual child (infant & toddler)Virtual child (infant & toddler)
Virtual child (infant & toddler)khiara_albaran
 

En vedette (20)

RDBMS and SQL
RDBMS and SQLRDBMS and SQL
RDBMS and SQL
 
RDBMS concepts
RDBMS conceptsRDBMS concepts
RDBMS concepts
 
Sql
SqlSql
Sql
 
Database Systems - Introduction to SQL (Chapter 3/1)
Database Systems - Introduction to SQL (Chapter 3/1)Database Systems - Introduction to SQL (Chapter 3/1)
Database Systems - Introduction to SQL (Chapter 3/1)
 
El 13 de diciembre
El 13 de diciembreEl 13 de diciembre
El 13 de diciembre
 
El 22 de febrero
El 22 de febreroEl 22 de febrero
El 22 de febrero
 
El 6 de enero
El 6 de eneroEl 6 de enero
El 6 de enero
 
Helping agencies
Helping agenciesHelping agencies
Helping agencies
 
4 b nadal alicia
4 b   nadal alicia4 b   nadal alicia
4 b nadal alicia
 
El 23 de febrero
El 23 de febreroEl 23 de febrero
El 23 de febrero
 
El 2 de enero
El 2 de eneroEl 2 de enero
El 2 de enero
 
El 3 de enero
El 3 de eneroEl 3 de enero
El 3 de enero
 
El 10 de febrero
El 10 de febrero El 10 de febrero
El 10 de febrero
 
El 14 de febrero
El 14 de febreroEl 14 de febrero
El 14 de febrero
 
IGPS I Assignment 4: Overarching Presentation
IGPS I Assignment 4: Overarching PresentationIGPS I Assignment 4: Overarching Presentation
IGPS I Assignment 4: Overarching Presentation
 
El nueve de marzo
El nueve de marzoEl nueve de marzo
El nueve de marzo
 
El 19 de diciembre
El 19 de diciembreEl 19 de diciembre
El 19 de diciembre
 
El 11 de enero
El 11 de eneroEl 11 de enero
El 11 de enero
 
Virtual child (infant & toddler)
Virtual child (infant & toddler)Virtual child (infant & toddler)
Virtual child (infant & toddler)
 
Nadal2011
Nadal2011Nadal2011
Nadal2011
 

Similaire à RDBMS SQL Basics

SQL Complete Tutorial. All Topics Covered
SQL Complete Tutorial. All Topics CoveredSQL Complete Tutorial. All Topics Covered
SQL Complete Tutorial. All Topics CoveredDanish Mehraj
 
MIS5101 WK10 Outcome Measures
MIS5101 WK10 Outcome MeasuresMIS5101 WK10 Outcome Measures
MIS5101 WK10 Outcome MeasuresSteven Johnson
 
Advanced Database Systems - Presentation 2.pptx
Advanced Database Systems - Presentation 2.pptxAdvanced Database Systems - Presentation 2.pptx
Advanced Database Systems - Presentation 2.pptxEllenGracePorras
 
SQL.pptx for the begineers and good know
SQL.pptx for the begineers and good knowSQL.pptx for the begineers and good know
SQL.pptx for the begineers and good knowPavithSingh
 
Introduction to Databases - query optimizations for MySQL
Introduction to Databases - query optimizations for MySQLIntroduction to Databases - query optimizations for MySQL
Introduction to Databases - query optimizations for MySQLMárton Kodok
 
Relational Database Language.pptx
Relational Database Language.pptxRelational Database Language.pptx
Relational Database Language.pptxSheethal Aji Mani
 
Data Base Management System.pdf
Data Base Management System.pdfData Base Management System.pdf
Data Base Management System.pdfTENZING LHADON
 
Intro To TSQL - Unit 1
Intro To TSQL - Unit 1Intro To TSQL - Unit 1
Intro To TSQL - Unit 1iccma
 
Intro to tsql unit 1
Intro to tsql   unit 1Intro to tsql   unit 1
Intro to tsql unit 1Syed Asrarali
 

Similaire à RDBMS SQL Basics (20)

Sql tutorial
Sql tutorialSql tutorial
Sql tutorial
 
SQL Complete Tutorial. All Topics Covered
SQL Complete Tutorial. All Topics CoveredSQL Complete Tutorial. All Topics Covered
SQL Complete Tutorial. All Topics Covered
 
lovely
lovelylovely
lovely
 
MIS5101 WK10 Outcome Measures
MIS5101 WK10 Outcome MeasuresMIS5101 WK10 Outcome Measures
MIS5101 WK10 Outcome Measures
 
T-SQL Overview
T-SQL OverviewT-SQL Overview
T-SQL Overview
 
PT- Oracle session01
PT- Oracle session01 PT- Oracle session01
PT- Oracle session01
 
Advanced Database Systems - Presentation 2.pptx
Advanced Database Systems - Presentation 2.pptxAdvanced Database Systems - Presentation 2.pptx
Advanced Database Systems - Presentation 2.pptx
 
SQL.pptx for the begineers and good know
SQL.pptx for the begineers and good knowSQL.pptx for the begineers and good know
SQL.pptx for the begineers and good know
 
Module02
Module02Module02
Module02
 
Rdbms day3
Rdbms day3Rdbms day3
Rdbms day3
 
Introduction to Databases - query optimizations for MySQL
Introduction to Databases - query optimizations for MySQLIntroduction to Databases - query optimizations for MySQL
Introduction to Databases - query optimizations for MySQL
 
PO WER - Piotr Mariat - Sql
PO WER - Piotr Mariat - SqlPO WER - Piotr Mariat - Sql
PO WER - Piotr Mariat - Sql
 
Relational Database Language.pptx
Relational Database Language.pptxRelational Database Language.pptx
Relational Database Language.pptx
 
7. SQL.pptx
7. SQL.pptx7. SQL.pptx
7. SQL.pptx
 
SKILLWISE-DB2 DBA
SKILLWISE-DB2 DBASKILLWISE-DB2 DBA
SKILLWISE-DB2 DBA
 
Introduction to SQL
Introduction to SQLIntroduction to SQL
Introduction to SQL
 
Data Base Management System.pdf
Data Base Management System.pdfData Base Management System.pdf
Data Base Management System.pdf
 
Data base
Data baseData base
Data base
 
Intro To TSQL - Unit 1
Intro To TSQL - Unit 1Intro To TSQL - Unit 1
Intro To TSQL - Unit 1
 
Intro to tsql unit 1
Intro to tsql   unit 1Intro to tsql   unit 1
Intro to tsql unit 1
 

Dernier

Conf42-LLM_Adding Generative AI to Real-Time Streaming Pipelines
Conf42-LLM_Adding Generative AI to Real-Time Streaming PipelinesConf42-LLM_Adding Generative AI to Real-Time Streaming Pipelines
Conf42-LLM_Adding Generative AI to Real-Time Streaming PipelinesTimothy Spann
 
Learn How Data Science Changes Our World
Learn How Data Science Changes Our WorldLearn How Data Science Changes Our World
Learn How Data Science Changes Our WorldEduminds Learning
 
Defining Constituents, Data Vizzes and Telling a Data Story
Defining Constituents, Data Vizzes and Telling a Data StoryDefining Constituents, Data Vizzes and Telling a Data Story
Defining Constituents, Data Vizzes and Telling a Data StoryJeremy Anderson
 
Easter Eggs From Star Wars and in cars 1 and 2
Easter Eggs From Star Wars and in cars 1 and 2Easter Eggs From Star Wars and in cars 1 and 2
Easter Eggs From Star Wars and in cars 1 and 217djon017
 
Data Analysis Project Presentation: Unveiling Your Ideal Customer, Bank Custo...
Data Analysis Project Presentation: Unveiling Your Ideal Customer, Bank Custo...Data Analysis Project Presentation: Unveiling Your Ideal Customer, Bank Custo...
Data Analysis Project Presentation: Unveiling Your Ideal Customer, Bank Custo...Boston Institute of Analytics
 
wepik-insightful-infographics-a-data-visualization-overview-20240401133220kwr...
wepik-insightful-infographics-a-data-visualization-overview-20240401133220kwr...wepik-insightful-infographics-a-data-visualization-overview-20240401133220kwr...
wepik-insightful-infographics-a-data-visualization-overview-20240401133220kwr...KarteekMane1
 
Advanced Machine Learning for Business Professionals
Advanced Machine Learning for Business ProfessionalsAdvanced Machine Learning for Business Professionals
Advanced Machine Learning for Business ProfessionalsVICTOR MAESTRE RAMIREZ
 
6 Tips for Interpretable Topic Models _ by Nicha Ruchirawat _ Towards Data Sc...
6 Tips for Interpretable Topic Models _ by Nicha Ruchirawat _ Towards Data Sc...6 Tips for Interpretable Topic Models _ by Nicha Ruchirawat _ Towards Data Sc...
6 Tips for Interpretable Topic Models _ by Nicha Ruchirawat _ Towards Data Sc...Dr Arash Najmaei ( Phd., MBA, BSc)
 
SMOTE and K-Fold Cross Validation-Presentation.pptx
SMOTE and K-Fold Cross Validation-Presentation.pptxSMOTE and K-Fold Cross Validation-Presentation.pptx
SMOTE and K-Fold Cross Validation-Presentation.pptxHaritikaChhatwal1
 
Networking Case Study prepared by teacher.pptx
Networking Case Study prepared by teacher.pptxNetworking Case Study prepared by teacher.pptx
Networking Case Study prepared by teacher.pptxHimangsuNath
 
Student profile product demonstration on grades, ability, well-being and mind...
Student profile product demonstration on grades, ability, well-being and mind...Student profile product demonstration on grades, ability, well-being and mind...
Student profile product demonstration on grades, ability, well-being and mind...Seán Kennedy
 
Predictive Analysis for Loan Default Presentation : Data Analysis Project PPT
Predictive Analysis for Loan Default  Presentation : Data Analysis Project PPTPredictive Analysis for Loan Default  Presentation : Data Analysis Project PPT
Predictive Analysis for Loan Default Presentation : Data Analysis Project PPTBoston Institute of Analytics
 
Student Profile Sample report on improving academic performance by uniting gr...
Student Profile Sample report on improving academic performance by uniting gr...Student Profile Sample report on improving academic performance by uniting gr...
Student Profile Sample report on improving academic performance by uniting gr...Seán Kennedy
 
What To Do For World Nature Conservation Day by Slidesgo.pptx
What To Do For World Nature Conservation Day by Slidesgo.pptxWhat To Do For World Nature Conservation Day by Slidesgo.pptx
What To Do For World Nature Conservation Day by Slidesgo.pptxSimranPal17
 
Digital Marketing Plan, how digital marketing works
Digital Marketing Plan, how digital marketing worksDigital Marketing Plan, how digital marketing works
Digital Marketing Plan, how digital marketing worksdeepakthakur548787
 
Bank Loan Approval Analysis: A Comprehensive Data Analysis Project
Bank Loan Approval Analysis: A Comprehensive Data Analysis ProjectBank Loan Approval Analysis: A Comprehensive Data Analysis Project
Bank Loan Approval Analysis: A Comprehensive Data Analysis ProjectBoston Institute of Analytics
 
Semantic Shed - Squashing and Squeezing.pptx
Semantic Shed - Squashing and Squeezing.pptxSemantic Shed - Squashing and Squeezing.pptx
Semantic Shed - Squashing and Squeezing.pptxMike Bennett
 
Minimizing AI Hallucinations/Confabulations and the Path towards AGI with Exa...
Minimizing AI Hallucinations/Confabulations and the Path towards AGI with Exa...Minimizing AI Hallucinations/Confabulations and the Path towards AGI with Exa...
Minimizing AI Hallucinations/Confabulations and the Path towards AGI with Exa...Thomas Poetter
 
Decoding the Heart: Student Presentation on Heart Attack Prediction with Data...
Decoding the Heart: Student Presentation on Heart Attack Prediction with Data...Decoding the Heart: Student Presentation on Heart Attack Prediction with Data...
Decoding the Heart: Student Presentation on Heart Attack Prediction with Data...Boston Institute of Analytics
 

Dernier (20)

Data Analysis Project: Stroke Prediction
Data Analysis Project: Stroke PredictionData Analysis Project: Stroke Prediction
Data Analysis Project: Stroke Prediction
 
Conf42-LLM_Adding Generative AI to Real-Time Streaming Pipelines
Conf42-LLM_Adding Generative AI to Real-Time Streaming PipelinesConf42-LLM_Adding Generative AI to Real-Time Streaming Pipelines
Conf42-LLM_Adding Generative AI to Real-Time Streaming Pipelines
 
Learn How Data Science Changes Our World
Learn How Data Science Changes Our WorldLearn How Data Science Changes Our World
Learn How Data Science Changes Our World
 
Defining Constituents, Data Vizzes and Telling a Data Story
Defining Constituents, Data Vizzes and Telling a Data StoryDefining Constituents, Data Vizzes and Telling a Data Story
Defining Constituents, Data Vizzes and Telling a Data Story
 
Easter Eggs From Star Wars and in cars 1 and 2
Easter Eggs From Star Wars and in cars 1 and 2Easter Eggs From Star Wars and in cars 1 and 2
Easter Eggs From Star Wars and in cars 1 and 2
 
Data Analysis Project Presentation: Unveiling Your Ideal Customer, Bank Custo...
Data Analysis Project Presentation: Unveiling Your Ideal Customer, Bank Custo...Data Analysis Project Presentation: Unveiling Your Ideal Customer, Bank Custo...
Data Analysis Project Presentation: Unveiling Your Ideal Customer, Bank Custo...
 
wepik-insightful-infographics-a-data-visualization-overview-20240401133220kwr...
wepik-insightful-infographics-a-data-visualization-overview-20240401133220kwr...wepik-insightful-infographics-a-data-visualization-overview-20240401133220kwr...
wepik-insightful-infographics-a-data-visualization-overview-20240401133220kwr...
 
Advanced Machine Learning for Business Professionals
Advanced Machine Learning for Business ProfessionalsAdvanced Machine Learning for Business Professionals
Advanced Machine Learning for Business Professionals
 
6 Tips for Interpretable Topic Models _ by Nicha Ruchirawat _ Towards Data Sc...
6 Tips for Interpretable Topic Models _ by Nicha Ruchirawat _ Towards Data Sc...6 Tips for Interpretable Topic Models _ by Nicha Ruchirawat _ Towards Data Sc...
6 Tips for Interpretable Topic Models _ by Nicha Ruchirawat _ Towards Data Sc...
 
SMOTE and K-Fold Cross Validation-Presentation.pptx
SMOTE and K-Fold Cross Validation-Presentation.pptxSMOTE and K-Fold Cross Validation-Presentation.pptx
SMOTE and K-Fold Cross Validation-Presentation.pptx
 
Networking Case Study prepared by teacher.pptx
Networking Case Study prepared by teacher.pptxNetworking Case Study prepared by teacher.pptx
Networking Case Study prepared by teacher.pptx
 
Student profile product demonstration on grades, ability, well-being and mind...
Student profile product demonstration on grades, ability, well-being and mind...Student profile product demonstration on grades, ability, well-being and mind...
Student profile product demonstration on grades, ability, well-being and mind...
 
Predictive Analysis for Loan Default Presentation : Data Analysis Project PPT
Predictive Analysis for Loan Default  Presentation : Data Analysis Project PPTPredictive Analysis for Loan Default  Presentation : Data Analysis Project PPT
Predictive Analysis for Loan Default Presentation : Data Analysis Project PPT
 
Student Profile Sample report on improving academic performance by uniting gr...
Student Profile Sample report on improving academic performance by uniting gr...Student Profile Sample report on improving academic performance by uniting gr...
Student Profile Sample report on improving academic performance by uniting gr...
 
What To Do For World Nature Conservation Day by Slidesgo.pptx
What To Do For World Nature Conservation Day by Slidesgo.pptxWhat To Do For World Nature Conservation Day by Slidesgo.pptx
What To Do For World Nature Conservation Day by Slidesgo.pptx
 
Digital Marketing Plan, how digital marketing works
Digital Marketing Plan, how digital marketing worksDigital Marketing Plan, how digital marketing works
Digital Marketing Plan, how digital marketing works
 
Bank Loan Approval Analysis: A Comprehensive Data Analysis Project
Bank Loan Approval Analysis: A Comprehensive Data Analysis ProjectBank Loan Approval Analysis: A Comprehensive Data Analysis Project
Bank Loan Approval Analysis: A Comprehensive Data Analysis Project
 
Semantic Shed - Squashing and Squeezing.pptx
Semantic Shed - Squashing and Squeezing.pptxSemantic Shed - Squashing and Squeezing.pptx
Semantic Shed - Squashing and Squeezing.pptx
 
Minimizing AI Hallucinations/Confabulations and the Path towards AGI with Exa...
Minimizing AI Hallucinations/Confabulations and the Path towards AGI with Exa...Minimizing AI Hallucinations/Confabulations and the Path towards AGI with Exa...
Minimizing AI Hallucinations/Confabulations and the Path towards AGI with Exa...
 
Decoding the Heart: Student Presentation on Heart Attack Prediction with Data...
Decoding the Heart: Student Presentation on Heart Attack Prediction with Data...Decoding the Heart: Student Presentation on Heart Attack Prediction with Data...
Decoding the Heart: Student Presentation on Heart Attack Prediction with Data...
 

RDBMS SQL Basics

  • 2. What is SQL SQL stands for Structured Query Language ● It is used to access, manipulate and process data in databases.
  • 3. What is a database? A database is a place that stores data, derived information and process logic. Common Forms: ● RDBMS - Relational Database Management System ● NoSQL - a grab bag of multiple systems to store data
  • 4. Parts of a RDBMS ● Database / Catalog ● Schema ● Table/ Indices ● View ● Row / Record ● Field / Column ● Stored Procedures/ Functions
  • 5. Column / Field A column (or field) is a single piece of data, that has a defined type and a set purpose ● Text ● Number ● more complex types depend on the RDBMS
  • 6. Record / Row A record is a collection of fields grouped together to provide context to the data contained
  • 7. Table / Indices A table is a collection of records which set operations can be applied to
  • 8. So what? Why is this useful, a database provides a means to represent real world models and hence understand through analysis more about the system modelled
  • 9. Data Modelling 101 What to model? ● Groceries ● Contact list ● Calendar You choose :)
  • 10. What were those join-ey things ● They can relate tables to each other ● Provide links to information for context ● Minimize storage
  • 11. Database Forms First Normal Form ● Eliminate repeating groups in individual tables. ● Create a separate table for each set of related data. ● Identify each set of related data with a primary key.
  • 12. Database Forms Second Normal Form ● Create separate tables for sets of values that apply to multiple records. ● Relate these tables with a foreign key.
  • 13. Database Forms Third Normal Form ● Eliminate fields that do not depend on the key
  • 14. So how do I get data? SELECT statment ● Allows you to SELECT data FROM several tables WHERE certain constraints exist, and GROUP BY certain fields, it can be ORDER BY other fields
  • 16. JOINS There are various join types in SQL INNER LEFT OUTER LEFT OUTER …. ON t2.field IS NULL FULL OUTER
  • 17. Joins... SELECT … FROM employee e INNER JOIN jobtitle j ON e.jobId = j.jobId
  • 18. Nested Tables SELECT … FROM ( SELECT … FROM employee ) subTable
  • 19. More Complexity... Depending on the platform we have function that can help process, manipulate and pivot data
  • 20. CASE statements CASE WHEN x THEN y ELSE z END AS simpleCase
  • 21. Common Table Expressions... WITH tableDef(fieldlist) AS ( … complex query ) SELECT ….
  • 22. Recursive CTE... WITH empTree AS ( SELECT …, 0 AS level FROM employee UNION ALL SELECT …, level + 1 AS level FROM employee INNER JOIN empTree ON ...
  • 23. PIVOT and UNPIVOT SELECT 'AverageCost' AS Cost_Sorted_By_Production_Days, [0], [1], [2], [3], [4] FROM (SELECT DaysToManufacture, StandardCost FROM Production.Product) AS SourceTable PIVOT ( AVG(StandardCost) FOR DaysToManufacture IN ([0], [1], [2], [3], [4]) ) AS PivotTable;
  • 24. LAG SELECT BusinessEntityID, YEAR(QuotaDate) AS SalesYear, SalesQuota AS CurrentQuota, LAG(SalesQuota, 1,0) OVER (ORDER BY YEAR(QuotaDate)) AS PreviousQuota FROM Sales.SalesPersonQuotaHistory WHERE BusinessEntityID = 275 and YEAR(QuotaDate) IN ('2005','2006');
  • 25. Designing complex SQL Diagram the flow Model the output Doodle :)