
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.
INT → whole numbers (e.g., 1, 2, 100)
VARCHAR(n) → text up to n characters (e.g., ‘Alice’)
DATE → dates (e.g., 2025-09-04)
DECIMAL(10,2) → numbers with decimals (e.g., 199.99)
What Are Primary and Foreign Keys? The Keys to Relational Data
Primary Key → uniquely identifies each row
Foreign Key → links one table to another
Example:
Customers Table
+----+----------+
| ID | Name |
+----+----------+
| 1 | Alice |
| 2 | Bob |
+----+----------+
Orders Table
+----+-------------+----------+
| ID | Customer_ID | Product |
+----+-------------+----------+
| 1 | 1 | Laptop |
| 2 | 2 | Phone |
+----+-------------+----------+
Here:
Customers.ID
is the Primary Key.Orders.Customer_ID
is a Foreign Key that referencesCustomers.ID
.
✅ 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.