Skip to main content

πŸ“˜ Data Operations

Welcome to the Data Operations module! This module we will learn how to add and remove the data from the table. For adding new data we can use INSERT INTO.

πŸ“˜ Inserting new data to SQL Table​

This module we will learn how to add and remove the data from the table. For adding new data we can use INSERT INTO.

Insert Into inserts a new row filled with a new data into existing table.

Then values add spesfic data to the newly added row. It spesfies the value to be inserted into a newly created row. These columns define the type of information stored for each item in the table.

For example, consider a table named Orders. Below is how a simple table might look:

info
Orders Table
| name           | id   | price |
|----------------|------|-------|
| Chocolate box | 1235 | 14 |
| Bath bombs | 2337 | 9 |
| Flower hamper | 7483 | 21 |

βœ… This is your first step in understanding how data is structured in relational databases. Once you master rows, you're on your way to writing powerful SQL queries!

tip

You can delete the data from an entire table by not spesfying the condition, this is known as Truncating. You can delete all value from the table using DELETE FROM without the condition.

By following these best practices,

πŸ”„ Deleting Data from SQL​

info
Orders Table
| name           | id   | price |
|----------------|------|-------|
| Chocolate box | 1235 | 14 |
| Bath bombs | 2337 | 9 |
| Flower hamper | 7483 | 21 |
| Old console | 6574 | 13 |

🧹 Deleting all the values​

Sometimes your table might contain duplicate values, and you only want to see each unique value once in your result.

That’s where the DELETE keyword comes in!


info
Users
| name  | id    | password |
|-------|-------|----------|
| Anita | 12345 | hello123 |
| Peter | 66574 | pete543 |
| Alex | 98732 | alexOOl |

:::

🧹 Updating the data​

Sometimes you need to update the existing table entries for sample scenario dinner reservation for guest booking in a restaurent This example shows how to update the reservation time for a specific guest in the Reservations table without creating duplicate entries.

Update cannot be used to insert new entries into table it can be only used to change existing entries. An Update statment always starts with the keyword UPDATE Followed by the table name. Then the table name is followed by the KEYWORD SET and an expression settng the colomn to specified value. As you noticed the UPDATE can be used to update a coloumns value for every row, but often we want to change spesfic row. we can do that by WHERE A condition > can be used to update multiple coloumn


info
Reservations
| Id | name    | phonenumtoer   | time  | partysae |
|----|---------|----------------|-------|----------|
| 1 | Powers | +16352637463 | 1800 | 4 |
| 2 | Miranda | +17487652839 | 1900 | 5 |
| 3 | Smith | +17648373572 | 18:30 | 3 |

You can see the change happened to Smith


βœ… What You Have Learned​

This module covers four key operations for managing data within SQL tables:

  • Inserting Data
    Use INSERT INTO to add new rows to a table, specifying values for each column.

  • Deleting Data
    Learn how to remove specific rows with DELETE FROM ... WHERE or remove all rows without a condition.

  • Updating Data
    Use UPDATE ... SET ... WHERE to modify existing rows without creating duplicates, targeting specific entries with conditions.

  • Truncating Data
    Understand how deleting all rows from a table clears its content, useful for removing duplicates or resetting tables.