Welcome to the SQL Puzzles tutorial, where we'll learn SQL by solving engaging and practical problems! This tutorial is perfect for beginners and intermediates. Let's dive in! 💡
SQL (Structured Query Language) is a standard language for managing and manipulating databases. It's used to communicate with databases, creating, modifying, and querying data.
Understanding SQL is crucial for developers as it helps in creating, managing, and maintaining the data infrastructure of applications and websites.
Before we begin, make sure you have a SQL server installed on your machine. For this tutorial, we'll use sqlite3 which comes pre-installed on many systems.
Let's create a new database named my_database.
sqlite3 my_databaseNow, let's create a table named students with some columns.
CREATE TABLE students (
id INTEGER PRIMARY KEY,
name TEXT,
age INTEGER,
gender TEXT
);Time to insert some data into the students table.
INSERT INTO students (name, age, gender) VALUES ('John', 23, 'Male');
INSERT INTO students (name, age, gender) VALUES ('Jane', 22, 'Female');Now, let's query the data from the students table.
SELECT * FROM students;Sometimes, we need to update existing data. Let's update John's age.
UPDATE students SET age = 24 WHERE name = 'John';If necessary, we can delete data from the table.
DELETE FROM students WHERE name = 'Jane';SQL queries are used to retrieve, manipulate, and update data in a database. Here are some basic SQL queries:
SELECT: Retrieves data from a databaseINSERT INTO: Inserts new data into a tableUPDATE: Modifies existing data in a tableDELETE: Removes data from a tableWhat SQL command is used to retrieve data from a database?