All questions
Showing of 44What is SQL and what are its main components?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
SQL, short for Structured Query Language, is the standard language for defining, querying and changing data in a relational database. It is declarative, meaning you describe the result and the database decides how to get it. MySQL, PostgreSQL and SQL Server are engines that implement SQL, each with its own extensions.
Its statements fall into four groups:
- Data Definition Language (DDL) defines structure with
CREATE,ALTERandDROP.TRUNCATEcounts as DDL too. - Data Manipulation Language (DML) reads data with
SELECTand changes it withINSERT,UPDATEandDELETE. - Data Control Language (DCL) controls access permissions with
GRANTandREVOKE. - Transaction Control Language (TCL) manages transactions with
COMMIT,ROLLBACKandSAVEPOINT.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
What's the difference between DELETE, TRUNCATE, and DROP?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
DELETE removes chosen rows, TRUNCATE removes every row but keeps the table, and DROP removes the table itself along with its data.
DELETEremoves the rows itsWHEREclause matches, one row at a time. Delete triggers fire, the change can be rolled back, and it is slow on large tables.TRUNCATEempties the whole table without scanning it, so it is much faster thanDELETE. It does not fire delete triggers, and MySQL and SQL Server also reset the auto-increment counter.DROPdeletes the table definition together with its data, indexes and constraints.
Rollback depends on the engine. MySQL commits TRUNCATE and DROP immediately, so neither can be rolled back there. PostgreSQL and SQL Server can roll back a TRUNCATE inside a transaction.
DELETE FROM employees WHERE age > 65; -- Removes specific rows
TRUNCATE TABLE employees; -- Removes all rows, keeps table
DROP TABLE employees; -- Removes entire table
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
What is a Primary Key and what are its characteristics?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
A primary key is the column, or set of columns, that uniquely identifies each row in a table. The database enforces two rules on it: every value must be unique, and no value may be NULL.
A table can have only one primary key, and the database creates an index on it automatically, so lookups by key are fast. Key values should also stay stable once assigned, because foreign keys point at them, but that is a design rule the database does not enforce.
A UNIQUE constraint also blocks duplicates, and a table can have several of them. Unlike a primary key, it accepts NULL. PostgreSQL and MySQL allow many NULL values in a unique column, while SQL Server allows only one.
CREATE TABLE employees (
emp_id INT PRIMARY KEY,
name VARCHAR(100) NOT NULL
);
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
What's the difference between WHERE and HAVING clauses?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
WHERE filters individual rows before they are grouped, and HAVING filters the groups after GROUP BY has formed them.
WHERE runs first, so it cannot use aggregate functions such as COUNT or AVG, because the groups do not exist yet. HAVING runs after grouping, so it can test those results, such as keeping only departments with more than five employees.
A condition that needs no aggregate belongs in WHERE. Filtering early means fewer rows reach the grouping step, which makes the query cheaper.
-- WHERE filters before grouping
SELECT department, COUNT(*)
FROM employees
WHERE salary > 50000
GROUP BY department;
-- HAVING filters after grouping
SELECT department, COUNT(*)
FROM employees
GROUP BY department
HAVING COUNT(*) > 5;
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
What's the difference between UNION and UNION ALL?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
UNION combines the rows of two queries and removes duplicate rows, while UNION ALL combines them and keeps every row, duplicates included.
Removing duplicates costs work, because the database has to sort or hash the combined rows to find repeats. So UNION ALL is usually faster. UNION also removes repeats that sit inside one input, not only the ones shared by both.
Both need the same number of columns in each query, in the same order, with compatible data types. The result takes its column names from the first query.
Use UNION ALL when the rows are already distinct, or when duplicates carry meaning, such as when counting events. Use UNION when each distinct row should appear once.
SELECT name FROM employees_2023
UNION -- Removes duplicates
SELECT name FROM employees_2024;
SELECT name FROM employees_2023
UNION ALL -- Keeps all rows
SELECT name FROM employees_2024;
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
What are constraints and what types are available?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
Constraints are rules the database enforces on column values, so bad data is rejected when it is written. The main types are:
NOT NULLstops a column from holdingNULL.UNIQUEstops two rows from sharing a value.PRIMARY KEYcombinesNOT NULLandUNIQUEto identify each row.FOREIGN KEYkeeps referential integrity by requiring each value to match a row in another table.CHECKrejects values that fail a condition, such as a total of zero or less.DEFAULTsupplies a value when an insert gives none.
A CHECK also passes when its condition is NULL, so pair it with NOT NULL when the column must have a value.
CREATE TABLE orders (
order_id INT PRIMARY KEY,
customer_id INT NOT NULL,
order_date DATE DEFAULT (CURRENT_DATE),
total_amount DECIMAL(10,2) CHECK (total_amount > 0),
FOREIGN KEY (customer_id) REFERENCES customers(id)
);
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
How do you handle NULL values in SQL?
What's the difference between a view and a table?
What's the difference between CHAR and VARCHAR data types?
What are the different types of database relationships?
What are aggregate functions and how do they work with GROUP BY?
How do you perform case-insensitive searches in SQL?
What are SQL's built-in functions, and what types exist?
What do INTERSECT and EXCEPT do, and how do they differ from UNION?
Explain the different types of SQL JOINs.
Explain the concept of database normalization and its forms.
What are indexes and how do they improve query performance?
What are subqueries and what types exist?
Explain the difference between clustered and non-clustered indexes.
What are Common Table Expressions (CTEs) and when would you use them?
What are stored procedures and their advantages?
What's the difference between correlated and non-correlated subqueries?
What are triggers and when should you use them?
How do you find duplicate records in a table?
Explain the execution order of SQL clauses.
What's the difference between RANK(), DENSE_RANK(), and ROW_NUMBER()?
Explain the concept of database transactions.
What are the advantages and disadvantages of using indexes?
What's the difference between EXISTS and IN operators?
How do you implement pagination in SQL?
What are user-defined functions and how do they differ from stored procedures?
What is a self-join and when would you use it?
What do the LAG and LEAD window functions do?
How do you write an upsert in SQL, and why avoid select-then-insert?
Explain ACID properties in database transactions.
What are Window Functions and how do they differ from aggregate functions?
How do you calculate running totals and moving averages?
Explain SQL injection and how to prevent it.
Explain different isolation levels in databases.
How do you optimize slow SQL queries?
Explain the concept of database locks and their types.
How do you handle hierarchical data in SQL?
How do you implement row-level security in SQL?
Explain database partitioning and its benefits.
This answer is part of Pro.
The full written answer, with the trade-offs and follow-ups an interviewer will probe.
No matches
Try a different filter or search term.
SQL Fundamentals cheatsheet
- How SQL works01
- Tables, keys & constraints02
- Insert, update & delete03
- Filter, group & sort04
- Joins & set operators05
- Subqueries & CTEs06
- Window functions07
- Indexes & query speed08
- Transactions & locks09
- Views, procedures & security10
- The model11
- + 5 more inside
38 of 44 SQL Fundamentals answers are in Pro.
Full answers, code samples, and AI explanations that go simpler or deeper. Cancel anytime.
- Full answers + code
- AI explanations, simpler or deeper
- 1,000 AI credits / month
- Cancel anytime
Change topic
Pick a different technology or stack. Your current topic stays put until you choose a new one.
MEAN
MongoDB, Express, Angular, Node.jsMERN
MongoDB, Express, React, Node.jsDjango
Python Full-Stack DevelopmentRuby on Rails
Convention over ConfigurationServerless on AWS
Serverless Architecture on AWSInterviewers also test these - they're common to every stack, whichever one you picked above.
Flutter Mobile
Flutter Cross-Platform Mobile DevelopmentInterviewers also test these - they're common to every stack, whichever one you picked above.
Spring Boot
Enterprise Java Development.NET
Microsoft EcosystemVue
Vue.js, Vite, TypeScript, Tailwind, Node.jsGo Backend
Golang, gRPC, PostgreSQL, Redis, RabbitMQInterviewers also test these - they're common to every stack, whichever one you picked above.
FastAPI
Python, FastAPI, SQLAlchemy, PostgreSQLReact Native
React, TypeScript, Redux, FirebaseiOS Native
Swift, SwiftUI, UIKit, FirebaseAndroid Native
Java, Jetpack Compose, FirebaseDevOps / Platform
Docker, Kubernetes, Terraform, CI/CDInterviewers also test these - they're common to every stack, whichever one you picked above.
AI Engineer
LLMs, RAG, Agents, EvalsAI-Powered Developer
Claude Code, Copilot, Agentic WorkflowsCore SWE Interview Prep
Data structures, algorithms, OS, concurrency, networking, gitInterviewers also test these - they're common to every stack, whichever one you picked above.
Interviewers also test these - they're common to every stack, whichever one you picked above.