🏆 OSM

SQL Data Manipulation and Definition Basics: INSERT, UPDATE, DELETE, CREATE TABLE, and Keys Explained

2 weeks ago
2025-09-04 11:31:33

Data Manipulation and Definition

More Than Just Queries: Using INSERT, UPDATE, and DELETE

SQL isn’t just for reading data — you can also add, change, or remove rows.

INSERT → Add new data

INSERT INTO Customers (ID, Name, City)
VALUES (1, 'Alice', 'London');

UPDATE → Change existing data

UPDATE Customers
SET City = 'Paris'
WHERE Name = 'Alice';

DELETE → Remove data

DELETE FROM Customers
WHERE Name = 'Alice';

Building Your Blueprints: A Guide to CREATE TABLE

A table is like a blueprint for your data. You define columns and their data types.

CREATE TABLE Customers (
    ID INT,
    Name VARCHAR(50),
    City VARCHAR(50)
);

This creates a table with 3 columns: ID, Name, and City.


The Power of ALTER TABLE: Modifying Your Database Structure

What if you want to add a new column later? Use ALTER TABLE.

ALTER TABLE Customers
ADD Phone VARCHAR(20);

Now your Customers table looks like this:

+----+----------+-------------+------------+
| ID | Name     | City        | Phone      |
+----+----------+-------------+------------+

Understanding SQL Data Types: From VARCHAR to INT

Every column has a data type, which defines what kind of data it stores.


What Are Primary and Foreign Keys? The Keys to Relational Data

Example:

Customers Table

+----+----------+
| ID | Name     |
+----+----------+
| 1  | Alice    |
| 2  | Bob      |
+----+----------+

Orders Table

+----+-------------+----------+
| ID | Customer_ID | Product  |
+----+-------------+----------+
| 1  | 1           | Laptop   |
| 2  | 2           | Phone    |
+----+-------------+----------+

Here:


✅ Pro Tip

Always define Primary Keys in your tables. Without them, it’s easy to create duplicate or messy data. Foreign Keys help keep relationships between tables clean and accurate.

Previous Blog

Core SQL Querying Skills for Beginners: WHERE, ORDER BY, and JOINs Explained Simply

Next Blog

SQL Aggregation and Grouping for Beginners: COUNT, SUM, AVG, GROUP BY, and HAVING Explained

© 2025 Oscar Myo Min

Design by Kai

𝕏 GitHub