SlideShare une entreprise Scribd logo
1  sur  31
Télécharger pour lire hors ligne
SQL Basics
Create, Read, Update, Delete
What Does SQL Look Like?
Like This:

SELECT ID FROM OrderTbl;
Where Do I Go To Type SQL
Statements?
You need a database.

Then you need one of these connected to it:
  ● A mySQL command prompt
  ● An installed app database query tool
  ● A web based database query tool

We are going to be using a web based
database query tool named phpMyAdmin.
An Example Database Table
                   OrderTbl

  ID     Name          Address      Product


  1      Alf           111 Street   Mask A


  2      Barry         222 Street   Mask B

  3      Charlie       333 Street   Mask C
Table Layout, Columns
Columns: ID, Name, Address, Product

The ID Column Contains Values: 1, 2, 3
  ID         Name      Address      Product


  1          Alf       111 Street   Mask A



  2          Barry     222 Street   Mask B



  3          Charlie   333 Street   Mask C
Table Layout, Rows
Row 1:
● ID is 1
● Name is Alf
● Address is 111 Street
● Product is Mask A
  ID        Name          Address      Product

  1         Alf           111 Street   Mask A

  2         Barry         222 Street   Mask B

  3         Charlie       333 Street   Mask C
Common SQL Keywords
SELECT - Read From Table

UPDATE - Edit Table aka Edit A Row

DELETE - Delete Row From Table

INSERT - Write To Table aka Add Rows
Reading All Data From OrderTbl
Reading = SELECT statement

Example Format:

SELECT <columns> FROM <table>;
Reading All Data From OrderTbl
Here is the SQL to get all row data from the
whole table:

SELECT ID, Name, Address, Product
FROM OrderTbl;

Result:
  1          Alf        111 Street   Mask A

  2          Barry      222 Street   Mask B

  3          Charlie    333 Street   Mask C
Breaking Down SQL Statement Parts
Original Statement:

SELECT ID, Name, Address, Product
FROM OrderTbl;

SELECT - "Read From Table"
ID, Name, Address, Product - "These Columns"
FROM - "Which Table?"
OrderTbl - "This Table"
Reading Only 2 Columns
SELECT ID, Product
FROM OrderTbl;

Result:

  ID                 Product

  1                  Mask A

  2                  Mask B

  3                  Mask C
The ID, A Very Special Column
The ID row can be used to talk about the whole
row...

ID 1's row or row 1 has Alf, 111 Street, Mask A


  ID         Name       Address      Product

  1          Alf        111 Street   Mask A

  2          Barry      222 Street   Mask B

  3          Charlie    333 Street   Mask C
The WHERE command
Structure:

WHERE <column name> = <value>

Examples:

WHERE ID = 1
WHERE Street = '111 Street'
WHERE Product = 'Mask A';
SELECT + WHERE Command
SELECT ID, Product
FROM OrderTbl
WHERE ID = 1;

In English:

Read the ID and Product column values in any
row of OrderTbl where the ID column's value is
1
Reading Only 2 Columns
SELECT ID, Product
FROM OrderTbl
WHERE ID = 1;

Result:


  ID                 Product

  1                  Mask A
SELECTing All Columns Easily
Instead of:

SELECT ID, Name, Address, Product
FROM OrderTbl;

SQL gives you the shortcut:

SELECT * FROM OrderTbl;
SELECTing All Columns Easily
Warning:

If you use the * command on large tables, it will
result in very slow processing times.

It is a shortcut you will see used, but it is
clearer to the reader and a better practice to
type out only the column names you need
Editing An Existing Row Of OrderTbl
Edit = UPDATE statement

Example Format:

UPDATE <table name>
SET <column1> = <value1>
WHERE <column2> = <value2>;
Editing An Existing Row Of OrderTbl
Here is the SQL to update the row 2's name
column to Johnny:

UPDATE OrderTbl SET Name = 'Johnny'
WHERE ID = 2;

English:

Update the Name column of the OrderTbl table
row with an ID of 2 to 'Johnny'
Editing An Existing Row Of OrderTbl
Before:
   ID               Name

   2                Barry


UPDATE OrderTbl SET Name = 'Johnny'
WHERE ID = 2;

After:

   ID               Name

   2                Johnny
Delete A Given OrderTbl Row
Delete = DELETE statement

Example Format:

DELETE FROM <table name>
WHERE <column> = <value>;
Delete A Given OrderTbl Row
Here is the SQL to delete the third row:

DELETE FROM OrderTbl WHERE ID = 3;

English:

Delete all the rows from OrderTbl where the ID
is 3.
Delete A Given OrderTbl Row
Before:
   ID              Name

   2               Barry

   3               Charlie


DELETE FROM OrderTbl WHERE ID = 3

After:

   ID              Name

   2               Barry
Delete A Given OrderTbl Row
Delete A Given OrderTbl Row
When Crafting DELETE Statements:

●   There is no undo button

●   Always give your delete statement a
    WHERE clause
Delete A Given OrderTbl Row
Bad:

DELETE FROM OrderTbl;


Better:

DELETE FROM OrderTbl WHERE ID = 3;
Writing A New Row To OrderTbl
Create = INSERT statement

Example Format:

INSERT INTO <table name>
(<column1>, <column2>, <column3>)
VALUES
(<value1>, <value2>, <value3>);
Writing A New Row To OrderTbl
INSERT INTO OrderTbl
(Name, Address, Product)
VALUES
('Danny', 'Street 444', 'Mask D');

Create a new row where the column Name is
Danny, Address is Street 444 and Product is
Mask D
Writing A New Row To OrderTbl
Before, nothing.

INSERT INTO OrderTbl (Name, Address,
Product) VALUES ('Danny', 'Street 444', 'Mask
D');

After

   ID        Name      Address      Product

   4         Danny     Street 444   Mask D
Auto Incrementing IDs
Notice that we did not define the ID column in
our INSERT statement, yet the value after it
was run was 4.

Each column of your table can be defined as a
number or text. If you define it as a number,
you can add an attribute to it called auto
increment.

This makes every next row increment by 1. The
ID row of next INSERT will be 5.
That's All For Today!
Next time:

●   JOINs
●   SQL modifiers (OR, AND, IN)
●   SQL symbols (%)
●   COUNT
●   Indexes and PKs
●   UNIONs (the free market variety...)

Contenu connexe

Dernier

9892124323, Call Girls in mumbai, Vashi Call Girls , Kurla Call girls
9892124323, Call Girls in mumbai, Vashi Call Girls , Kurla Call girls9892124323, Call Girls in mumbai, Vashi Call Girls , Kurla Call girls
9892124323, Call Girls in mumbai, Vashi Call Girls , Kurla Call girlsPooja Nehwal
 
Understanding Relationship Anarchy: A Guide to Liberating Love | CIO Women Ma...
Understanding Relationship Anarchy: A Guide to Liberating Love | CIO Women Ma...Understanding Relationship Anarchy: A Guide to Liberating Love | CIO Women Ma...
Understanding Relationship Anarchy: A Guide to Liberating Love | CIO Women Ma...CIOWomenMagazine
 
Lilac Illustrated Social Psychology Presentation.pptx
Lilac Illustrated Social Psychology Presentation.pptxLilac Illustrated Social Psychology Presentation.pptx
Lilac Illustrated Social Psychology Presentation.pptxABMWeaklings
 
CALL ON ➥8923113531 🔝Call Girls Mahanagar Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Mahanagar Lucknow best sexual serviceCALL ON ➥8923113531 🔝Call Girls Mahanagar Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Mahanagar Lucknow best sexual serviceanilsa9823
 
文凭办理《原版美国USU学位证书》犹他州立大学毕业证制作成绩单修改
文凭办理《原版美国USU学位证书》犹他州立大学毕业证制作成绩单修改文凭办理《原版美国USU学位证书》犹他州立大学毕业证制作成绩单修改
文凭办理《原版美国USU学位证书》犹他州立大学毕业证制作成绩单修改atducpo
 
Lucknow 💋 High Class Call Girls Lucknow 10k @ I'm VIP Independent Escorts Gir...
Lucknow 💋 High Class Call Girls Lucknow 10k @ I'm VIP Independent Escorts Gir...Lucknow 💋 High Class Call Girls Lucknow 10k @ I'm VIP Independent Escorts Gir...
Lucknow 💋 High Class Call Girls Lucknow 10k @ I'm VIP Independent Escorts Gir...anilsa9823
 
办理国外毕业证学位证《原版美国montana文凭》蒙大拿州立大学毕业证制作成绩单修改
办理国外毕业证学位证《原版美国montana文凭》蒙大拿州立大学毕业证制作成绩单修改办理国外毕业证学位证《原版美国montana文凭》蒙大拿州立大学毕业证制作成绩单修改
办理国外毕业证学位证《原版美国montana文凭》蒙大拿州立大学毕业证制作成绩单修改atducpo
 
CALL ON ➥8923113531 🔝Call Girls Aliganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Aliganj Lucknow best sexual serviceCALL ON ➥8923113531 🔝Call Girls Aliganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Aliganj Lucknow best sexual serviceanilsa9823
 
Call Girls in Kalyan Vihar Delhi 💯 Call Us 🔝8264348440🔝
Call Girls in Kalyan Vihar Delhi 💯 Call Us 🔝8264348440🔝Call Girls in Kalyan Vihar Delhi 💯 Call Us 🔝8264348440🔝
Call Girls in Kalyan Vihar Delhi 💯 Call Us 🔝8264348440🔝soniya singh
 
Call Girls In Andheri East Call US Pooja📞 9892124323 Book Hot And
Call Girls In Andheri East Call US Pooja📞 9892124323 Book Hot AndCall Girls In Andheri East Call US Pooja📞 9892124323 Book Hot And
Call Girls In Andheri East Call US Pooja📞 9892124323 Book Hot AndPooja Nehwal
 
《塔夫斯大学毕业证成绩单购买》做Tufts文凭毕业证成绩单/伪造美国假文凭假毕业证书图片Q微信741003700《塔夫斯大学毕业证购买》《Tufts毕业文...
《塔夫斯大学毕业证成绩单购买》做Tufts文凭毕业证成绩单/伪造美国假文凭假毕业证书图片Q微信741003700《塔夫斯大学毕业证购买》《Tufts毕业文...《塔夫斯大学毕业证成绩单购买》做Tufts文凭毕业证成绩单/伪造美国假文凭假毕业证书图片Q微信741003700《塔夫斯大学毕业证购买》《Tufts毕业文...
《塔夫斯大学毕业证成绩单购买》做Tufts文凭毕业证成绩单/伪造美国假文凭假毕业证书图片Q微信741003700《塔夫斯大学毕业证购买》《Tufts毕业文...ur8mqw8e
 
办理西悉尼大学毕业证成绩单、制作假文凭
办理西悉尼大学毕业证成绩单、制作假文凭办理西悉尼大学毕业证成绩单、制作假文凭
办理西悉尼大学毕业证成绩单、制作假文凭o8wvnojp
 
REFLECTIONS Newsletter Jan-Jul 2024.pdf.pdf
REFLECTIONS Newsletter Jan-Jul 2024.pdf.pdfREFLECTIONS Newsletter Jan-Jul 2024.pdf.pdf
REFLECTIONS Newsletter Jan-Jul 2024.pdf.pdfssusere8ea60
 
8377087607 Full Enjoy @24/7-CLEAN-Call Girls In Chhatarpur,
8377087607 Full Enjoy @24/7-CLEAN-Call Girls In Chhatarpur,8377087607 Full Enjoy @24/7-CLEAN-Call Girls In Chhatarpur,
8377087607 Full Enjoy @24/7-CLEAN-Call Girls In Chhatarpur,dollysharma2066
 
call girls in candolim beach 9870370636] NORTH GOA ..
call girls in candolim beach 9870370636] NORTH GOA ..call girls in candolim beach 9870370636] NORTH GOA ..
call girls in candolim beach 9870370636] NORTH GOA ..nishakur201
 
Breath, Brain & Beyond_A Holistic Approach to Peak Performance.pdf
Breath, Brain & Beyond_A Holistic Approach to Peak Performance.pdfBreath, Brain & Beyond_A Holistic Approach to Peak Performance.pdf
Breath, Brain & Beyond_A Holistic Approach to Peak Performance.pdfJess Walker
 
Dhule Call Girls #9907093804 Contact Number Escorts Service Dhule
Dhule Call Girls #9907093804 Contact Number Escorts Service DhuleDhule Call Girls #9907093804 Contact Number Escorts Service Dhule
Dhule Call Girls #9907093804 Contact Number Escorts Service Dhulesrsj9000
 
Call Girls Anjuna beach Mariott Resort ₰8588052666
Call Girls Anjuna beach Mariott Resort ₰8588052666Call Girls Anjuna beach Mariott Resort ₰8588052666
Call Girls Anjuna beach Mariott Resort ₰8588052666nishakur201
 

Dernier (20)

9892124323, Call Girls in mumbai, Vashi Call Girls , Kurla Call girls
9892124323, Call Girls in mumbai, Vashi Call Girls , Kurla Call girls9892124323, Call Girls in mumbai, Vashi Call Girls , Kurla Call girls
9892124323, Call Girls in mumbai, Vashi Call Girls , Kurla Call girls
 
escort service sasti (*~Call Girls in Paschim Vihar Metro❤️9953056974
escort service  sasti (*~Call Girls in Paschim Vihar Metro❤️9953056974escort service  sasti (*~Call Girls in Paschim Vihar Metro❤️9953056974
escort service sasti (*~Call Girls in Paschim Vihar Metro❤️9953056974
 
Model Call Girl in Lado Sarai Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Lado Sarai Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Lado Sarai Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Lado Sarai Delhi reach out to us at 🔝9953056974🔝
 
Understanding Relationship Anarchy: A Guide to Liberating Love | CIO Women Ma...
Understanding Relationship Anarchy: A Guide to Liberating Love | CIO Women Ma...Understanding Relationship Anarchy: A Guide to Liberating Love | CIO Women Ma...
Understanding Relationship Anarchy: A Guide to Liberating Love | CIO Women Ma...
 
Lilac Illustrated Social Psychology Presentation.pptx
Lilac Illustrated Social Psychology Presentation.pptxLilac Illustrated Social Psychology Presentation.pptx
Lilac Illustrated Social Psychology Presentation.pptx
 
CALL ON ➥8923113531 🔝Call Girls Mahanagar Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Mahanagar Lucknow best sexual serviceCALL ON ➥8923113531 🔝Call Girls Mahanagar Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Mahanagar Lucknow best sexual service
 
文凭办理《原版美国USU学位证书》犹他州立大学毕业证制作成绩单修改
文凭办理《原版美国USU学位证书》犹他州立大学毕业证制作成绩单修改文凭办理《原版美国USU学位证书》犹他州立大学毕业证制作成绩单修改
文凭办理《原版美国USU学位证书》犹他州立大学毕业证制作成绩单修改
 
Lucknow 💋 High Class Call Girls Lucknow 10k @ I'm VIP Independent Escorts Gir...
Lucknow 💋 High Class Call Girls Lucknow 10k @ I'm VIP Independent Escorts Gir...Lucknow 💋 High Class Call Girls Lucknow 10k @ I'm VIP Independent Escorts Gir...
Lucknow 💋 High Class Call Girls Lucknow 10k @ I'm VIP Independent Escorts Gir...
 
办理国外毕业证学位证《原版美国montana文凭》蒙大拿州立大学毕业证制作成绩单修改
办理国外毕业证学位证《原版美国montana文凭》蒙大拿州立大学毕业证制作成绩单修改办理国外毕业证学位证《原版美国montana文凭》蒙大拿州立大学毕业证制作成绩单修改
办理国外毕业证学位证《原版美国montana文凭》蒙大拿州立大学毕业证制作成绩单修改
 
CALL ON ➥8923113531 🔝Call Girls Aliganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Aliganj Lucknow best sexual serviceCALL ON ➥8923113531 🔝Call Girls Aliganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Aliganj Lucknow best sexual service
 
Call Girls in Kalyan Vihar Delhi 💯 Call Us 🔝8264348440🔝
Call Girls in Kalyan Vihar Delhi 💯 Call Us 🔝8264348440🔝Call Girls in Kalyan Vihar Delhi 💯 Call Us 🔝8264348440🔝
Call Girls in Kalyan Vihar Delhi 💯 Call Us 🔝8264348440🔝
 
Call Girls In Andheri East Call US Pooja📞 9892124323 Book Hot And
Call Girls In Andheri East Call US Pooja📞 9892124323 Book Hot AndCall Girls In Andheri East Call US Pooja📞 9892124323 Book Hot And
Call Girls In Andheri East Call US Pooja📞 9892124323 Book Hot And
 
《塔夫斯大学毕业证成绩单购买》做Tufts文凭毕业证成绩单/伪造美国假文凭假毕业证书图片Q微信741003700《塔夫斯大学毕业证购买》《Tufts毕业文...
《塔夫斯大学毕业证成绩单购买》做Tufts文凭毕业证成绩单/伪造美国假文凭假毕业证书图片Q微信741003700《塔夫斯大学毕业证购买》《Tufts毕业文...《塔夫斯大学毕业证成绩单购买》做Tufts文凭毕业证成绩单/伪造美国假文凭假毕业证书图片Q微信741003700《塔夫斯大学毕业证购买》《Tufts毕业文...
《塔夫斯大学毕业证成绩单购买》做Tufts文凭毕业证成绩单/伪造美国假文凭假毕业证书图片Q微信741003700《塔夫斯大学毕业证购买》《Tufts毕业文...
 
办理西悉尼大学毕业证成绩单、制作假文凭
办理西悉尼大学毕业证成绩单、制作假文凭办理西悉尼大学毕业证成绩单、制作假文凭
办理西悉尼大学毕业证成绩单、制作假文凭
 
REFLECTIONS Newsletter Jan-Jul 2024.pdf.pdf
REFLECTIONS Newsletter Jan-Jul 2024.pdf.pdfREFLECTIONS Newsletter Jan-Jul 2024.pdf.pdf
REFLECTIONS Newsletter Jan-Jul 2024.pdf.pdf
 
8377087607 Full Enjoy @24/7-CLEAN-Call Girls In Chhatarpur,
8377087607 Full Enjoy @24/7-CLEAN-Call Girls In Chhatarpur,8377087607 Full Enjoy @24/7-CLEAN-Call Girls In Chhatarpur,
8377087607 Full Enjoy @24/7-CLEAN-Call Girls In Chhatarpur,
 
call girls in candolim beach 9870370636] NORTH GOA ..
call girls in candolim beach 9870370636] NORTH GOA ..call girls in candolim beach 9870370636] NORTH GOA ..
call girls in candolim beach 9870370636] NORTH GOA ..
 
Breath, Brain & Beyond_A Holistic Approach to Peak Performance.pdf
Breath, Brain & Beyond_A Holistic Approach to Peak Performance.pdfBreath, Brain & Beyond_A Holistic Approach to Peak Performance.pdf
Breath, Brain & Beyond_A Holistic Approach to Peak Performance.pdf
 
Dhule Call Girls #9907093804 Contact Number Escorts Service Dhule
Dhule Call Girls #9907093804 Contact Number Escorts Service DhuleDhule Call Girls #9907093804 Contact Number Escorts Service Dhule
Dhule Call Girls #9907093804 Contact Number Escorts Service Dhule
 
Call Girls Anjuna beach Mariott Resort ₰8588052666
Call Girls Anjuna beach Mariott Resort ₰8588052666Call Girls Anjuna beach Mariott Resort ₰8588052666
Call Girls Anjuna beach Mariott Resort ₰8588052666
 

En vedette

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
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
 

En vedette (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
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...
 

CPAP.com Introduction To SQL: Create, Read, Update, Delete

  • 1. SQL Basics Create, Read, Update, Delete
  • 2. What Does SQL Look Like? Like This: SELECT ID FROM OrderTbl;
  • 3. Where Do I Go To Type SQL Statements? You need a database. Then you need one of these connected to it: ● A mySQL command prompt ● An installed app database query tool ● A web based database query tool We are going to be using a web based database query tool named phpMyAdmin.
  • 4. An Example Database Table OrderTbl ID Name Address Product 1 Alf 111 Street Mask A 2 Barry 222 Street Mask B 3 Charlie 333 Street Mask C
  • 5. Table Layout, Columns Columns: ID, Name, Address, Product The ID Column Contains Values: 1, 2, 3 ID Name Address Product 1 Alf 111 Street Mask A 2 Barry 222 Street Mask B 3 Charlie 333 Street Mask C
  • 6. Table Layout, Rows Row 1: ● ID is 1 ● Name is Alf ● Address is 111 Street ● Product is Mask A ID Name Address Product 1 Alf 111 Street Mask A 2 Barry 222 Street Mask B 3 Charlie 333 Street Mask C
  • 7. Common SQL Keywords SELECT - Read From Table UPDATE - Edit Table aka Edit A Row DELETE - Delete Row From Table INSERT - Write To Table aka Add Rows
  • 8. Reading All Data From OrderTbl Reading = SELECT statement Example Format: SELECT <columns> FROM <table>;
  • 9. Reading All Data From OrderTbl Here is the SQL to get all row data from the whole table: SELECT ID, Name, Address, Product FROM OrderTbl; Result: 1 Alf 111 Street Mask A 2 Barry 222 Street Mask B 3 Charlie 333 Street Mask C
  • 10. Breaking Down SQL Statement Parts Original Statement: SELECT ID, Name, Address, Product FROM OrderTbl; SELECT - "Read From Table" ID, Name, Address, Product - "These Columns" FROM - "Which Table?" OrderTbl - "This Table"
  • 11. Reading Only 2 Columns SELECT ID, Product FROM OrderTbl; Result: ID Product 1 Mask A 2 Mask B 3 Mask C
  • 12. The ID, A Very Special Column The ID row can be used to talk about the whole row... ID 1's row or row 1 has Alf, 111 Street, Mask A ID Name Address Product 1 Alf 111 Street Mask A 2 Barry 222 Street Mask B 3 Charlie 333 Street Mask C
  • 13. The WHERE command Structure: WHERE <column name> = <value> Examples: WHERE ID = 1 WHERE Street = '111 Street' WHERE Product = 'Mask A';
  • 14. SELECT + WHERE Command SELECT ID, Product FROM OrderTbl WHERE ID = 1; In English: Read the ID and Product column values in any row of OrderTbl where the ID column's value is 1
  • 15. Reading Only 2 Columns SELECT ID, Product FROM OrderTbl WHERE ID = 1; Result: ID Product 1 Mask A
  • 16. SELECTing All Columns Easily Instead of: SELECT ID, Name, Address, Product FROM OrderTbl; SQL gives you the shortcut: SELECT * FROM OrderTbl;
  • 17. SELECTing All Columns Easily Warning: If you use the * command on large tables, it will result in very slow processing times. It is a shortcut you will see used, but it is clearer to the reader and a better practice to type out only the column names you need
  • 18. Editing An Existing Row Of OrderTbl Edit = UPDATE statement Example Format: UPDATE <table name> SET <column1> = <value1> WHERE <column2> = <value2>;
  • 19. Editing An Existing Row Of OrderTbl Here is the SQL to update the row 2's name column to Johnny: UPDATE OrderTbl SET Name = 'Johnny' WHERE ID = 2; English: Update the Name column of the OrderTbl table row with an ID of 2 to 'Johnny'
  • 20. Editing An Existing Row Of OrderTbl Before: ID Name 2 Barry UPDATE OrderTbl SET Name = 'Johnny' WHERE ID = 2; After: ID Name 2 Johnny
  • 21. Delete A Given OrderTbl Row Delete = DELETE statement Example Format: DELETE FROM <table name> WHERE <column> = <value>;
  • 22. Delete A Given OrderTbl Row Here is the SQL to delete the third row: DELETE FROM OrderTbl WHERE ID = 3; English: Delete all the rows from OrderTbl where the ID is 3.
  • 23. Delete A Given OrderTbl Row Before: ID Name 2 Barry 3 Charlie DELETE FROM OrderTbl WHERE ID = 3 After: ID Name 2 Barry
  • 24. Delete A Given OrderTbl Row
  • 25. Delete A Given OrderTbl Row When Crafting DELETE Statements: ● There is no undo button ● Always give your delete statement a WHERE clause
  • 26. Delete A Given OrderTbl Row Bad: DELETE FROM OrderTbl; Better: DELETE FROM OrderTbl WHERE ID = 3;
  • 27. Writing A New Row To OrderTbl Create = INSERT statement Example Format: INSERT INTO <table name> (<column1>, <column2>, <column3>) VALUES (<value1>, <value2>, <value3>);
  • 28. Writing A New Row To OrderTbl INSERT INTO OrderTbl (Name, Address, Product) VALUES ('Danny', 'Street 444', 'Mask D'); Create a new row where the column Name is Danny, Address is Street 444 and Product is Mask D
  • 29. Writing A New Row To OrderTbl Before, nothing. INSERT INTO OrderTbl (Name, Address, Product) VALUES ('Danny', 'Street 444', 'Mask D'); After ID Name Address Product 4 Danny Street 444 Mask D
  • 30. Auto Incrementing IDs Notice that we did not define the ID column in our INSERT statement, yet the value after it was run was 4. Each column of your table can be defined as a number or text. If you define it as a number, you can add an attribute to it called auto increment. This makes every next row increment by 1. The ID row of next INSERT will be 5.
  • 31. That's All For Today! Next time: ● JOINs ● SQL modifiers (OR, AND, IN) ● SQL symbols (%) ● COUNT ● Indexes and PKs ● UNIONs (the free market variety...)