Stored — SQL Technical Interview Questions & Answers

Stored

Stored

  • Stored programs in MySQL: procedures, functions, triggers, events. They live in the database. The CLI needs a different DELIMITER to define them.
  • Functions: SELECT fn(marks). Procedures: CALL. Triggers: automatic. Events: scheduled (like a cron inside MySQL).
  • Trap: ‘stored’ as a vague word without saying which of the four.
  • On the example next to this theory: Stored: create two demo rows, then SELECT qty >= 2 ordered. Say which labels come back.

Technical Interview Tip: Four stored objects. DELIMITER when you CREATE them.

Code Examples for Stored

Stored — sample query

-- Stored
CREATE TABLE demo (
  id INTEGER PRIMARY KEY,
  label TEXT NOT NULL,
  qty INTEGER DEFAULT 0
);
INSERT INTO demo (id, label, qty) VALUES
  (1, 'alpha', 2),
  (2, 'beta', 5);
SELECT label, qty FROM demo WHERE qty >= 2 ORDER BY qty DESC;

Stored: create two demo rows, then SELECT qty >= 2 ordered. Say which labels come back.

How to Explain Stored to an Interviewer

Procedure vs function?

CALL vs SELECT fn() Function returns a value