SQL Exercises 🎯

beginner
16 min

SQL Exercises 🎯

Welcome to the SQL Exercises lesson! In this tutorial, you'll learn how to write SQL queries like a pro. Let's get started!

What is SQL? 📝

SQL (Structured Query Language) is a language used to communicate with databases. It allows you to create, manipulate, and query databases, making it essential for developers and data analysts.

Why SQL? 💡

SQL is used because it provides a standardized way to interact with databases regardless of the database management system (DBMS) or database type. With SQL, you can perform various tasks like creating tables, inserting data, querying data, and updating or deleting data.

Basic SQL Commands 💡

Creating a Database 🎯

First, let's create a database:

sql
CREATE DATABASE myDatabase;

Creating a Table 🎯

Now, let's create a table named students:

sql
CREATE TABLE students ( id INT PRIMARY KEY, name VARCHAR(255), age INT, gender VARCHAR(10) );

Inserting Data 🎯

Next, let's insert some data into the students table:

sql
INSERT INTO students (id, name, age, gender) VALUES (1, 'John Doe', 20, 'Male');

Querying Data 🎯

Finally, let's retrieve data from the students table:

sql
SELECT * FROM students;
Quick Quiz
Question 1 of 1

Which command is used to query data from a table?

Updating Data 🎯

Now, let's update John Doe's age:

sql
UPDATE students SET age = 21 WHERE name = 'John Doe';

Deleting Data 🎯

Lastly, let's delete John Doe's record:

sql
DELETE FROM students WHERE name = 'John Doe';

That's it for the basic SQL commands! In the next sections, we'll explore more advanced SQL concepts like joins, subqueries, and indexes.

Stay tuned! ✅