SlideShare a Scribd company logo
1 of 24
Download to read offline
Database for Everyone
Piti Champeethong (A.K.A Lutfy)
FB: fb.com/digitaloldschooljourney
Agenda
Morning Session Afternoon Session
- Normalization คืออะไร มี
อะไรบาง
- Workshop design
database
- Import data
- SQL101
- Trigger
- Stored Procedure
- User Defined Function
- Workshop query report
- Conclusion
Normalization
1NF - Eliminate Repeating Groups (Make a separate table for each
set of related attributes, and give each table a primary key)
2NF - A relation is in second normal form if it is in 1NF and
every non key attribute is fully functionally dependent on the
primary key.
3NF - A relation is in second normal form if it is in 2NF and
Every non-prime attribute of R is non-transitively dependent
on every key of R (Relation Table)
1NF (First Normal Form)
2NF (Second Normal Form)
3NF (Second Normal Form)
Azure Data Studio
https://bit.ly/2S4vdBV
Import data
- Setup extension from https://bit.ly/2CoUtgT
- Convert excel or any sources to CSV
- Import CSV by extension into database
Structure Query Language
[SELECT] - [FROM] - [WHERE] - [GROUP BY] - [HAVING] - [ORDER BY]
- SELECT FirstName, LastName FROM Employee
- SELECT * FROM Employee
- SELECT FirstName FROM Employee ORDER BY FirstName
- SELECT FirstName FROM Employee WHERE Department=’HR’
- SELECT FIrstName
FROM Employee
WHERE Department=’HR’
ORDER BY FirstName
JOIN Operator
SELECT FirstName, DepartmentName
FROM Employee
INNER JOIN Department ON EmployeeId.DepId = Department.DepId
SELECT FirstName, DepartmentName
FROM Employee
INNER JOIN Department ON EmployeeId.DepId = Department.DepId
INNER JOIN ControlManager ON ControlManager.MgrId =
Employee.MgrId
INNER JOIN
sLeft table Right table
INNER JOIN Ex:
INNER JOIN SQL:
SELECT ชื่อพนักงาน, แผนก
FROM ขอมูลพนักงาน as emp
INNER JOIN ขอมูลแผนก as dep
ON emp.รหัสแผนก = dep.รหัสแผนก
LEFT|RIGHT JOIN
s Right tableLeft table Left table Right table
LEFT JOIN Ex:
LEFT JOIN SQL:
SELECT รหัสพนักงาน, ชื่อพนักงาน, วันที่ลางาน
FROM ขอมูลพนักงาน as emp
LEFT JOIN ขอมูลการลางาน as leave
ON emp.รหัสพนักงาน = leave.รหัสพนักงาน
Query Processor
1. FROM
2. ON
3. JOIN
4. WHERE
5. GROUP BY
6. WITH CUBE or WITH
ROLLUP
7. HAVING
8. SELECT
9. DISTINCT
10. ORDER BY
11. TOP
Aggregation
1. COUNT - นับจํานวนแถวทั้งหมด (records)
2. MIN - หาคาที่ตํ่าที่สุด (minimize)
3. MAX - หาคามากที่สุด (maximize)
4. SUM - หาผลรวม (summation)
5. AVG - หาคาเฉลี่ย (average)
Trigger
การเขียนคําสั่ง T-SQL เพื่อสรางฟงกชั่นใหแทรกการทํา
งานในตารางขอมูล ใหทํางานบางอยางแบบอัตโนมัติ
Use-Case:
เมื่อผูใชลบขอมูลใดๆ ใหคัดลอกขอมูลที่ถูกลบเหลานั้น
ไปเก็บไวอีกตาราง
Stored Procedure
การเขียนคําสั่ง T-SQL เพื่อสรางฟงกชั่นเก็บเอาไวใช
สําหรับจัดการขอมูลตางๆ เพื่องานตอการเรียกมาใชใหม
Use-Case:
สรางฟงกชั่นเพื่อใชสําหรับเพิ่ม แกไข ลบ เรียกขอมูล
ตางๆ จากตารางเพื่อลด network traffic และขั้นตอนการ
ตรวจสอบขอมูล
Without SP
DB
Parser
Algibrizing
​Optimizer
Execution
Send query string
Receive results
ทุกครั้งที่มีการ request จะตองรันคําสั่ง 4 step ใน DB
With SP
DB
Parser
Algibrizing
​Optimizer
Execution
Send SP
Receive results
ทําแตขึ้นตอน Execution อยางเดียว เนื่องจากตอนสราง
SP ไดมีการตรวจสอบ 3 ขั้นตอนแรกไปแลว
Reference
- www.dofactory.com
- www.datacamp.com
- https://docs.microsoft.com/en-us/sql/azure-data-s
tudio/
Our sponsors

More Related Content

Featured

Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 

Featured (20)

Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 

Database101

  • 1. Database for Everyone Piti Champeethong (A.K.A Lutfy) FB: fb.com/digitaloldschooljourney
  • 2. Agenda Morning Session Afternoon Session - Normalization คืออะไร มี อะไรบาง - Workshop design database - Import data - SQL101 - Trigger - Stored Procedure - User Defined Function - Workshop query report - Conclusion
  • 3. Normalization 1NF - Eliminate Repeating Groups (Make a separate table for each set of related attributes, and give each table a primary key) 2NF - A relation is in second normal form if it is in 1NF and every non key attribute is fully functionally dependent on the primary key. 3NF - A relation is in second normal form if it is in 2NF and Every non-prime attribute of R is non-transitively dependent on every key of R (Relation Table)
  • 8. Import data - Setup extension from https://bit.ly/2CoUtgT - Convert excel or any sources to CSV - Import CSV by extension into database
  • 9. Structure Query Language [SELECT] - [FROM] - [WHERE] - [GROUP BY] - [HAVING] - [ORDER BY] - SELECT FirstName, LastName FROM Employee - SELECT * FROM Employee - SELECT FirstName FROM Employee ORDER BY FirstName - SELECT FirstName FROM Employee WHERE Department=’HR’ - SELECT FIrstName FROM Employee WHERE Department=’HR’ ORDER BY FirstName
  • 10. JOIN Operator SELECT FirstName, DepartmentName FROM Employee INNER JOIN Department ON EmployeeId.DepId = Department.DepId SELECT FirstName, DepartmentName FROM Employee INNER JOIN Department ON EmployeeId.DepId = Department.DepId INNER JOIN ControlManager ON ControlManager.MgrId = Employee.MgrId
  • 11. INNER JOIN sLeft table Right table
  • 13. INNER JOIN SQL: SELECT ชื่อพนักงาน, แผนก FROM ขอมูลพนักงาน as emp INNER JOIN ขอมูลแผนก as dep ON emp.รหัสแผนก = dep.รหัสแผนก
  • 14. LEFT|RIGHT JOIN s Right tableLeft table Left table Right table
  • 16. LEFT JOIN SQL: SELECT รหัสพนักงาน, ชื่อพนักงาน, วันที่ลางาน FROM ขอมูลพนักงาน as emp LEFT JOIN ขอมูลการลางาน as leave ON emp.รหัสพนักงาน = leave.รหัสพนักงาน
  • 17. Query Processor 1. FROM 2. ON 3. JOIN 4. WHERE 5. GROUP BY 6. WITH CUBE or WITH ROLLUP 7. HAVING 8. SELECT 9. DISTINCT 10. ORDER BY 11. TOP
  • 18. Aggregation 1. COUNT - นับจํานวนแถวทั้งหมด (records) 2. MIN - หาคาที่ตํ่าที่สุด (minimize) 3. MAX - หาคามากที่สุด (maximize) 4. SUM - หาผลรวม (summation) 5. AVG - หาคาเฉลี่ย (average)
  • 19. Trigger การเขียนคําสั่ง T-SQL เพื่อสรางฟงกชั่นใหแทรกการทํา งานในตารางขอมูล ใหทํางานบางอยางแบบอัตโนมัติ Use-Case: เมื่อผูใชลบขอมูลใดๆ ใหคัดลอกขอมูลที่ถูกลบเหลานั้น ไปเก็บไวอีกตาราง
  • 20. Stored Procedure การเขียนคําสั่ง T-SQL เพื่อสรางฟงกชั่นเก็บเอาไวใช สําหรับจัดการขอมูลตางๆ เพื่องานตอการเรียกมาใชใหม Use-Case: สรางฟงกชั่นเพื่อใชสําหรับเพิ่ม แกไข ลบ เรียกขอมูล ตางๆ จากตารางเพื่อลด network traffic และขั้นตอนการ ตรวจสอบขอมูล
  • 21. Without SP DB Parser Algibrizing ​Optimizer Execution Send query string Receive results ทุกครั้งที่มีการ request จะตองรันคําสั่ง 4 step ใน DB
  • 22. With SP DB Parser Algibrizing ​Optimizer Execution Send SP Receive results ทําแตขึ้นตอน Execution อยางเดียว เนื่องจากตอนสราง SP ไดมีการตรวจสอบ 3 ขั้นตอนแรกไปแลว
  • 23. Reference - www.dofactory.com - www.datacamp.com - https://docs.microsoft.com/en-us/sql/azure-data-s tudio/