Spring Boot & SQL Quick Notes
1. Spring Boot Features
- Auto Configuration
- Standalone Applications (Embedded Tomcat)
- Spring Initializr (start.spring.io)
- No XML Configuration Required
- Production-Ready with Spring Boot Actuator
- Starter Dependencies (spring-boot-starter-*)
- Externalized Configuration (application.properties/yml)
- Built-in Testing Support
- Rapid Development for Microservices
- Easy Integration with JPA, Kafka, Eureka, etc.
2. Spring Boot Tools
- Spring Boot Actuator
Provides monitoring & management endpoints like /actuator/health, /metrics.
- Spring Boot DevTools
Enables auto-restart, LiveReload, disables caching during dev.
- Spring Boot CLI
Command-line tool for running Spring apps using Groovy.
- Spring Boot Starters
Predefined dependency sets (web, data-jpa, security, etc.)
3. SQL Basics
- DML: SELECT, INSERT, UPDATE, DELETE
- DDL: CREATE, ALTER, DROP, TRUNCATE
- DELETE vs TRUNCATE: DELETE supports WHERE and rollback; TRUNCATE is faster, removes all row
- Constraints: PRIMARY KEY, UNIQUE, NOT NULL, CHECK, DEFAULT, FOREIGN KEY
- Joins: INNER, LEFT, RIGHT, FULL (use UNION for FULL in MySQL)
- Subqueries: Used inside other queries (WHERE, FROM, SELECT)
4. SQL Query Examples
- Find user with ID 24:
SELECT * FROM users WHERE id = 24;
- 2nd Highest Salary:
SELECT DISTINCT salary FROM employees ORDER BY salary DESC LIMIT 1 OFFSET 1;
OR
SELECT MAX(salary) FROM employees WHERE salary < (SELECT MAX(salary) FROM
employees);
- LIKE: SELECT * FROM users WHERE fname LIKE 'A%';
- BETWEEN: SELECT * FROM employees WHERE salary BETWEEN 40000 AND 80000;