Day 2:Python Programming
Source: Dev.to
Database Structure, Data Types & Table Basics
1. Database Structure Recap
A Relational Database contains:
- Database
- Tables
- Rows (Records)
- Columns (Fields)
Example
- Database →
school - Table →
students - Columns →
student_id,name,age,city
2. SQL Data Types (VERY IMPORTANT)
Numeric Data Types
| Data Type | Description | Example |
|---|---|---|
INT | Whole numbers | 10, 25 |
BIGINT | Large integers | 1,000,000 |
DECIMAL(p,s) | Decimal numbers | 99.50 |
String / Character Data Types
| Data Type | Description | Example |
|---|---|---|
CHAR(n) | Fixed‑length text | 'A' |
VARCHAR(n) | Variable‑length text | 'Aruna' |
TEXT | Large text | Address |
Date & Time Data Types
| Data Type | Description | Example |
|---|---|---|
DATE | YYYY‑MM‑DD | 2025-01-10 |
TIME | HH:MM:SS | 10:30:00 |
DATETIME | Date + Time | 2025-01-10 10:30:00 |
3. CREATE TABLE with Data Types
Defines table structure clearly.
CREATE TABLE employees (
emp_id INT,
emp_name VARCHAR(50),
salary DECIMAL(10,2),
join_date DATE
);
4. Viewing Table Structure
- Describe a table
DESCRIBE employees;
- Show all tables
SHOW TABLES;
5. INSERT Data (Detailed)
- Insert a single row
INSERT INTO employees (emp_id, emp_name, salary, join_date)
VALUES (101, 'Ravi', 35000.50, '2024-06-15');
- Insert multiple rows
INSERT INTO employees VALUES
(102, 'Priya', 42000.00, '2024-07-01'),
(103, 'Karthik', 38000.75, '2024-08-10');
6. SELECT Basics (More Detail)
- Select all columns
SELECT * FROM employees;
- Select specific columns
SELECT emp_name, salary FROM employees;
7. Table Naming Rules
- Use meaningful names.
- Avoid SQL keywords.
- Prefer lowercase with underscores.
Correct: employee_details
Incorrect: select, table