Retrieving and Updating Data SQL
Retrieving and Updating Data SQL
SQL
• A Beginner-Friendly Guide to Core SQL
Operations
• Your Name • Date • Class Info
What is SQL and a Database?
• SQL (Structured Query Language) is used to
manage databases.
• A database stores data in tables (like
spreadsheets).
• Each table has rows (records) and columns
(fields).
• Syntax:
• SELECT column1, column2 FROM table_name;
• Example:
• SELECT name, age FROM students;
• (Returns just the name and age of all
Using * and WHERE
• * selects all columns; WHERE filters rows
based on conditions.
• Example:
• SELECT * FROM students;
• (Get all data from students table.)
• Example:
• SELECT * FROM students ORDER BY age DESC;
• (Sorts by age in descending order.)
• Syntax:
• UPDATE table_name SET column1 = value1
WHERE condition;
• Example:
• UPDATE students SET age = 23 WHERE name =
Updating Multiple Columns
• You can update multiple values at once.
• Example:
• UPDATE students SET name = 'Janet Smith',
age = 24 WHERE id = 2;
• (Changes name and age for id 2.)
Verifying with SELECT
• After updating, use SELECT to confirm
changes.
• Example:
• SELECT * FROM students WHERE id = 2;
• (This checks if the update worked correctly.)
Real-World Flow Example
• 1. SELECT to view current data.
• 2. Identify incorrect/outdated info.
• 3. UPDATE to fix data.
• 4. SELECT again to verify changes.
• Practice at:
• - sqlbolt.com
• - w3schools.com/sql