Welcome to the SQL Exercises lesson! In this tutorial, you'll learn how to write SQL queries like a pro. Let's get started!
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.
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.
First, let's create a database:
CREATE DATABASE myDatabase;Now, let's create a table named students:
CREATE TABLE students (
id INT PRIMARY KEY,
name VARCHAR(255),
age INT,
gender VARCHAR(10)
);Next, let's insert some data into the students table:
INSERT INTO students (id, name, age, gender) VALUES (1, 'John Doe', 20, 'Male');Finally, let's retrieve data from the students table:
SELECT * FROM students;Which command is used to query data from a table?
Now, let's update John Doe's age:
UPDATE students SET age = 21 WHERE name = 'John Doe';Lastly, let's delete John Doe's record:
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! ✅