Database / SQLite Interview questions
What is the difference between INTEGER PRIMARY KEY and a regular PRIMARY KEY in SQLite?
Declaring a column as exactly INTEGER PRIMARY KEY makes it a direct alias for the table's
internal rowid, meaning lookups by that column hit the B-tree's key directly — the fastest
possible access path. A PRIMARY KEY on a non-integer column (or declared with
WITHOUT ROWID), or a composite primary key across multiple columns, doesn't get this same
rowid-aliasing behavior.
CREATE TABLE fast_lookup ( id INTEGER PRIMARY KEY, -- aliases rowid: fastest lookups name TEXT ); CREATE TABLE composite_key ( a TEXT, b TEXT, PRIMARY KEY (a, b) -- composite key; no rowid alias );
This distinction matters for performance-sensitive schema design: if a table's natural primary key is a
single integer, declaring it as INTEGER PRIMARY KEY gets you the fastest lookup path essentially
for free, whereas any other kind of primary key requires a normal (still efficient, but comparatively slower)
B-tree index traversal.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
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.
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! Receive free stock by signing up using the link: Webull signup.
More Related questions...
