SQL Database CommandsCheat Sheet
Master database operations with comprehensive SQL commands and examples
50+ Commands
All Skill Levels
Interview Ready
SELECT Statement
Retrieve data from one or more tables
SELECT column1, column2 FROM table_name WHERE condition;
basicinterviewdevelopment
Example:SELECT name, age FROM users WHERE age > 18;
Quick Tip:Always specify columns instead of using * for better performance
INSERT Statement
Add new records to a table
INSERT INTO table_name (column1, column2) VALUES (value1, value2);
basicinterviewdevelopment
Example:INSERT INTO users (name, email) VALUES ('John Doe', 'john@example.com');
Quick Tip:Use parameterized queries to prevent SQL injection
UPDATE Statement
Modify existing records in a table
UPDATE table_name SET column1 = value1 WHERE condition;
basicinterviewdevelopment
Example:UPDATE users SET age = 25 WHERE name = 'John Doe';
Quick Tip:Always use WHERE clause to avoid updating all rows
DELETE Statement
Remove records from a table
DELETE FROM table_name WHERE condition;
basicinterviewdevelopment
Example:DELETE FROM users WHERE age < 18;
Quick Tip:Be very careful with DELETE - always test with SELECT first
TRUNCATE TABLE
Remove all records from a table quickly
TRUNCATE TABLE table_name;
intermediatedevelopmentdatabase
Example:TRUNCATE TABLE temp_data;
Quick Tip:Faster than DELETE but cannot be rolled back in some databases
CREATE TABLE
Create a new table with specified columns and data types
CREATE TABLE table_name (column1 datatype, column2 datatype, ...);
basicdevelopmentdatabase
Example:CREATE TABLE users (id INT PRIMARY KEY, name VARCHAR(100), email VARCHAR(255));
Quick Tip:Always define primary keys and appropriate data types
ALTER TABLE
Modify existing table structure
ALTER TABLE table_name ADD/DROP/MODIFY column_name datatype;
intermediatedevelopmentdatabase
Example:ALTER TABLE users ADD phone VARCHAR(20);
Quick Tip:Be careful with DROP COLUMN - data will be lost permanently