Prev Next

Database / SQLite Interview questions

What is a TRIGGER in SQLite?

A TRIGGER is a piece of SQL logic that runs automatically in response to a specific table event — INSERT, UPDATE, or DELETE — either before or after that event occurs, without the application needing to explicitly call anything.

CREATE TRIGGER update_timestamp
AFTER UPDATE ON person
BEGIN
    UPDATE person SET updated_at = CURRENT_TIMESTAMP WHERE id = NEW.id;
END;

Common uses: automatically maintaining an "updated at" timestamp, enforcing business rules that go beyond what a simple constraint can express, logging changes to an audit table, or cascading a change to related data. Triggers run inside the same transaction as the statement that fired them, so if the trigger's logic fails, the whole original operation is rolled back along with it.

When does a TRIGGER run?
What happens if a trigger's logic fails?

Invest now in Acorns!!! 🚀 Join Acorns and get your $5 bonus!
Acorns Logo

Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!

Earn passively and while sleeping

Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.

Robinhood Logo

Invest now!!! Get Free equity stock (US, UK only)!

Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.

The Robinhood app makes it easy to trade stocks, crypto and more.


Webull Logo

Webull! Receive free stock by signing up using the link: Webull signup.

More Related questions...

What is SQLite? What are the key features of SQLite? How is SQLite different from client-server databases like MySQL or PostgreSQL? What is the file format of a SQLite database? What are the supported data types in SQLite? What is dynamic typing (type affinity) in SQLite? How do you create a table in SQLite? How do you insert data into a SQLite table? How do you query data from a SQLite table? How do you update a record in SQLite? How do you delete a record in SQLite? What is a PRIMARY KEY in SQLite? What is AUTOINCREMENT in SQLite? What is a UNIQUE constraint in SQLite? What is a FOREIGN KEY in SQLite and how do you enable it? What is the sqlite3 command-line shell used for? How do you create an index in SQLite? What is a NULL value in SQLite? What is the difference between CHAR, VARCHAR, and TEXT in SQLite? What is the ROWID in a SQLite table? What is an in-memory SQLite database? How do you back up a SQLite database? What is the PRAGMA statement used for? What is a VIEW in SQLite? What is a TRIGGER in SQLite? What is the difference between DELETE, TRUNCATE, and DROP in SQLite? What is a transaction in SQLite and how do you use BEGIN/COMMIT/ROLLBACK? What is the difference between WAL mode and rollback journal mode? Why does SQLite recommend enabling foreign keys explicitly, given they're off by default? What is the difference between INTEGER PRIMARY KEY and a regular PRIMARY KEY in SQLite? How does SQLite handle concurrent writes? What is the difference between a SQLite VIEW and a TABLE? How do you perform a JOIN in SQLite? What is an UPSERT in SQLite (INSERT... ON CONFLICT)? How do you use the EXPLAIN QUERY PLAN statement? What is a composite primary key in SQLite? How does SQLite handle database locking? What is the difference between VACUUM and ANALYZE in SQLite? Explain the internal working of SQLite's B-tree storage structure? How does WAL mode improve concurrency compared to the default rollback journal? Explain the lifecycle of a SQLite transaction from BEGIN to COMMIT? Why might full-text search (FTS5) be needed instead of a LIKE query? How do you optimize a slow SQLite query? What are the limitations of SQLite for large-scale, high-concurrency applications? How does SQLite ensure ACID compliance without a separate server process? Explain how SQLite's write-ahead logging (WAL) checkpoint process works? What isolation level does SQLite provide, compared to other RDBMS? What is the STRICT keyword used for in SQLite table definitions?
Show more question and Answers...

Integration

Comments & Discussions