Database / SQLite Interview questions
What is a composite primary key in SQLite?
A composite (or compound) primary key spans more than one column, with uniqueness enforced across the combination of those columns rather than any single one alone — useful for tables representing a many-to-many relationship, where the natural unique identifier really is a pair (or more) of values together.
CREATE TABLE enrollment ( student_id INTEGER, course_id INTEGER, PRIMARY KEY (student_id, course_id) ); -- the same student_id can appear multiple times (for different courses), -- and the same course_id can appear multiple times (for different students), -- but the (student_id, course_id) pair as a whole must be unique
Unlike a single-column INTEGER PRIMARY KEY, a composite primary key doesn't get the rowid-alias
performance shortcut — lookups against it go through a normal B-tree index traversal on the combined key,
still efficient, but not the absolute fastest single-integer lookup path.
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...
