CREATE TABLE defines a table's structure — each column's name, type and constraints. Choosing the right data type keeps data correct and storage efficient (this is DDL — data definition language).
Creating a table
CREATE TABLE students (id INT PRIMARY KEY AUTO_INCREMENT,name VARCHAR(100) NOT NULL,email VARCHAR(150) UNIQUE,package DECIMAL(5,2) DEFAULT 0.00,enrolled DATE,created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP);
Common types
| Type | Use for |
|---|---|
INT / BIGINT | Whole numbers, IDs |
DECIMAL(p,s) | Exact money/measures (never FLOAT for money) |
VARCHAR(n) | Short, variable-length text |
TEXT | Long text |
DATE / TIMESTAMP | Dates and times |
BOOLEAN | True/false |
Key takeaways
- 01CREATE TABLE defines columns, types and constraints (DDL).
- 02Match the type to the data: INT for IDs, VARCHAR for text, DATE/TIMESTAMP for time.
- 03Use DECIMAL for money — never FLOAT/DOUBLE.
- 04ALTER TABLE modifies structure later; DROP TABLE deletes the table.
