SQL CREATE, ALTER, DROP – Table & Database




💻 Introduction

Managing databases and tables in SQL is essential for any developer or analyst. In this guide, we’ll explore CREATE, ALTER, and DROP statements with clear examples you can practice instantly.

Before diving in, make sure you have a basic understanding of SQL basics and SQL Data Types.

1️⃣ SQL CREATE – Creating Databases and Tables

The CREATE statement is used to make new databases or tables.

Creating a Database

CREATE DATABASE RetailDB;

Creating a Table

CREATE TABLE Employees (
    EmpID INT PRIMARY KEY,
    FirstName VARCHAR(50),
    LastName VARCHAR(50),
    Salary DECIMAL(10,2),
    JoinDate DATE
);
Tip: Always define a PRIMARY KEY for your tables to uniquely identify records.

2️⃣ SQL ALTER – Modifying Tables

The ALTER statement lets you add, modify, or delete columns in an existing table.

Adding a Column

ALTER TABLE Employees
ADD Department VARCHAR(50);

Modifying a Column

ALTER TABLE Employees
MODIFY Salary DECIMAL(12,2);

Dropping a Column

ALTER TABLE Employees
DROP COLUMN Department;
Tip: Always backup your data before dropping columns or making structural changes.

3️⃣ SQL DROP – Deleting Tables and Databases

The DROP statement removes databases or tables permanently. Use with caution!

Dropping a Table

DROP TABLE Employees;

Dropping a Database

DROP DATABASE RetailDB;
Tip: Make sure you really want to delete the data because DROP is irreversible.

✅ Key Takeaways

  • CREATE → Make new databases or tables
  • ALTER → Modify table structure (add, change, remove columns)
  • DROP → Permanently remove tables or databases
  • Always define a PRIMARY KEY for tables
  • Backup your data before ALTER or DROP operations

📚 Continue Learning

💬 Got a question about SQL CREATE, ALTER, DROP? Drop it in the comments below and let’s discuss!




Leave a Comment