DBMS · core
Indexes, views, procedures and triggers
An index speeds up lookups. Views, procedures, functions and triggers keep logic in the database.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- A slow login can come from no index on email: the database reads all rows (a full table scan) for every login.
- A UNIQUE index on email turns that into a quick lookup. A B-tree index works like the index at the back of a book.
- An index costs disk space and makes inserts and updates a little slower. Add one for columns used often in WHERE, JOIN or ORDER BY, not on every column.
- Measure first: the slow query log, timings in the app and EXPLAIN on the query.
- View: a saved SELECT that looks like a table and stores no data. A materialized view stores the result and must be refreshed.
- Simple views (one table, no GROUP BY) can usually be updated. Views with joins or aggregates usually cannot.
- Stored procedure: named SQL with parameters, run with CALL or EXEC. It can change data and control a transaction. A function returns a value and can be used inside a SELECT.
- A trigger runs by itself when an event happens (insert, update or delete). The application does not call it.
The red pen
Common traps: mistake → fix
Mistake: A view is a copy of the table
Fix: it stores no data; it is a saved query.
Mistake: Index every column
Fix: each index slows writes and uses space.
Mistake: The app calls the trigger
Fix: the database runs it on the event.
Mistake: Buy a bigger server first
Fix: measure and check the index first.
Easy to hard
Questions interviewers ask, easy to hard
- Login is slow when 200 students log in together. What do you check?
- What is a view and when would you use one?
- What is the difference between a stored procedure and a function?
- What is a trigger?
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.