Add insert operations lesson

feat/course
Kamran Ahmed 3 weeks ago
parent f3ae9bbb87
commit ebce356165
  1. 2
      src/components/Course/CourseLayout.tsx
  2. 2
      src/data/courses/sql/chapters/defining-tables/defining-tables.md
  3. 0
      src/data/courses/sql/chapters/defining-tables/lessons/check-constraints.md
  4. 0
      src/data/courses/sql/chapters/defining-tables/lessons/common-data-types.md
  5. 0
      src/data/courses/sql/chapters/defining-tables/lessons/constraints-challenge.md
  6. 0
      src/data/courses/sql/chapters/defining-tables/lessons/creating-tables.md
  7. 0
      src/data/courses/sql/chapters/defining-tables/lessons/data-types-challenge.md
  8. 0
      src/data/courses/sql/chapters/defining-tables/lessons/data-types-in-sqlite.md
  9. 0
      src/data/courses/sql/chapters/defining-tables/lessons/dropping-or-truncate.md
  10. 0
      src/data/courses/sql/chapters/defining-tables/lessons/modifying-table.md
  11. 0
      src/data/courses/sql/chapters/defining-tables/lessons/modifying-tables.md
  12. 0
      src/data/courses/sql/chapters/defining-tables/lessons/numeric-types.md
  13. 0
      src/data/courses/sql/chapters/defining-tables/lessons/primary-key-constraint.md
  14. 0
      src/data/courses/sql/chapters/defining-tables/lessons/removing-table-data.md
  15. 0
      src/data/courses/sql/chapters/defining-tables/lessons/sales-data-analysis.md
  16. 0
      src/data/courses/sql/chapters/defining-tables/lessons/simple-table-creation.md
  17. 0
      src/data/courses/sql/chapters/defining-tables/lessons/temporal-data-types.md
  18. 0
      src/data/courses/sql/chapters/defining-tables/lessons/temporal-validation.md
  19. 75
      src/data/courses/sql/chapters/manipulating-data/lessons/insert-operations.md
  20. 5
      src/data/courses/sql/chapters/manipulating-data/manipulating-data.md
  21. 23
      src/data/courses/sql/chapters/sql-basics/lessons/select-fundamentals.md

@ -131,7 +131,7 @@ export function CourseLayout(props: CourseLayoutProps) {
: 'grid-rows-1',
)}
>
<div className="grid grid-cols-[240px_1fr] overflow-hidden">
<div className="grid grid-cols-[255px_1fr] overflow-hidden">
<CourseSidebar
{...sidebarProps}
completedPercentage={Number(courseProgressPercentage)}

@ -1,5 +1,5 @@
---
title: Data Definition Language
title: Defining Tables
description: Learn the basics of SQL, the language for querying databases.
order: 3
---

@ -0,0 +1,75 @@
---
title: INSERT Operations
description: Learn how to insert data into a table.
order: 100
type: lesson-challenge
---
In our previous chapter, we learned all about Data Definition Language (DDL) i.e. how to create, modify and delete tables. This chapter is all about Data Manipulation Language (DML) i.e. doing the same but for data i.e. inserting, updating and deleting data.
In this lesson, we will learn how to insert data into a table.
## What is an INSERT Operation?
An `INSERT` operation is used to add new rows to a table. It allows you to specify the values for each column in the new row.
For example, let's say we have a table called `books` with the following columns:
| id | title | author | price |
| --- | --------------------- | ------------------- | ----- |
| 1 | The Great Gatsby | F. Scott Fitzgerald | 10.99 |
| 2 | 1984 | George Orwell | 12.99 |
| 3 | To Kill a Mockingbird | Harper Lee | 8.99 |
We can insert a new row into this table using:
```sql
INSERT INTO books (id, title, author, price)
VALUES (4, 'The Catcher in the Rye', 'J.D. Salinger', 9.99);
```
This statement will add a new row to the `books` table with the following values:
| id | title | author | price |
| --- | ---------------------- | ------------- | ----- |
| 4 | The Catcher in the Rye | J.D. Salinger | 9.99 |
We can also insert multiple rows at once using:
```sql
INSERT INTO books (id, title, author, price)
VALUES (4, 'The Great Gatsby', 'F. Scott Fitzgerald', 10.99),
(5, 'Pride and Prejudice', 'Jane Austen', 11.99),
(6, 'The Hobbit', 'J.R.R. Tolkien', 13.99),
(7, 'The Lord of the Rings', 'J.R.R. Tolkien', 14.99);
```
This will insert the following 4 rows into the `books` table:
| id | title | author | price |
| --- | --------------------- | ------------------- | ----- |
| 4 | The Great Gatsby | F. Scott Fitzgerald | 10.99 |
| 5 | Pride and Prejudice | Jane Austen | 11.99 |
| 6 | The Hobbit | J.R.R. Tolkien | 13.99 |
| 7 | The Lord of the Rings | J.R.R. Tolkien | 14.99 |
---
## Challenge
I have already created a `books` table with the following columns:
| Column Name | Data Type |
| ----------- | -------------- |
| id | INTEGER |
| title | VARCHAR(250) |
| author | VARCHAR(250) |
| price | DECIMAL(10, 2) |
Insert the following 3 rows into the `books` table:
| id | title | author | price |
| --- | ---------------------- | ------------- | ----- |
| 8 | The Catcher in the Rye | J.D. Salinger | 9.99 |
| 9 | 1984 | George Orwell | 12.99 |
| 10 | To Kill a Mockingbird | Harper Lee | 8.99 |

@ -0,0 +1,5 @@
---
title: Manipulating Data
description: Learn the basics of SQL, the language for querying databases.
order: 4
---

@ -18,12 +18,11 @@ Here, `column1, column2, ...` are the columns we want to retrieve from the table
Let's take a hypothetical example of an online store that sells books. Imagine we have a table called `books` containing all the books available for sale with following data:
| id | title | author | price |
|----|-------|--------|-------|
| 1 | The Great Gatsby | F. Scott Fitzgerald | 10.99 |
| 2 | 1984 | George Orwell | 12.99 |
| 3 | To Kill a Mockingbird | Harper Lee | 8.99 |
| id | title | author | price |
| --- | --------------------- | ------------------- | ----- |
| 1 | The Great Gatsby | F. Scott Fitzgerald | 10.99 |
| 2 | 1984 | George Orwell | 12.99 |
| 3 | To Kill a Mockingbird | Harper Lee | 8.99 |
## Selecting All Columns
@ -35,6 +34,8 @@ SELECT * FROM books;
The `*` symbol is a wildcard character that represents all columns. This query will return all the columns from the `books` table.
> Notice that we end our query with a semicolon `;`. This is a common convention in SQL to indicate the end of a query. However, it is not mandatory and can be omitted if you want unless you are running multiple queries in a single file.
## Selecting Specific Columns
To get only the `title` and `author` columns from the `books` table, we would write the following SQL query:
@ -51,8 +52,8 @@ This query will return only the `title` and `author` columns from the `books` ta
Taking the same `books` table, write an SQL query to get the `title` and `price` columns from the `books` table. Your output should look like this:
| title | price |
|-------|-------|
| The Great Gatsby | 10.99 |
| 1984 | 12.99 |
| To Kill a Mockingbird | 8.99 |
| title | price |
| --------------------- | ----- |
| The Great Gatsby | 10.99 |
| 1984 | 12.99 |
| To Kill a Mockingbird | 8.99 |

Loading…
Cancel
Save