A primary key uniquely identifies each row in a table. It’s like an Aadhaar number for database records—no two rows can have the same one. It ensures data integrity and helps retrieve records quickly.
Interview Flashcards & Mock Mode
Practice with 3D flip cards, voice reader, and timed interview simulations.
CodeShot.in — Daily Challenges
60-second in-browser coding micro-challenges to sharpen syntax and problem-solving speed.
What is a primary key in MySQL and why is it important?
What is an index in MySQL and how does it improve performance?
An index speeds up data retrieval by creating a lookup structure. Just like a book index helps you jump to a page instead of reading the whole book, database indexes allow faster searches but slightly slow down inserts and updates.
What is a transaction in MySQL?
A transaction groups multiple database operations into a single unit of work. Either all operations succeed or all fail. It’s like a bank transfer—money must be debited and credited together or not at all.
What are ACID properties?
ACID stands for Atomicity, Consistency, Isolation, and Durability. These properties ensure transactions are reliable and data remains correct even during failures.
What is database normalization?
Normalization organizes data to reduce duplication and improve consistency. It’s like storing customer details once instead of repeating them in every order.
What is the difference between SQL JOIN types (INNER, LEFT, RIGHT, FULL)?
JOIN combines rows from two tables based on a related column. INNER JOIN returns only matching rows. LEFT JOIN returns all rows from the left table and matching ones from the right. RIGHT JOIN is the opposite. FULL JOIN returns everything. Think of it like two guest lists—INNER is people on both lists, LEFT is everyone from list A plus matches from list B.
When would you use a LEFT JOIN over an INNER JOIN?
Use LEFT JOIN when you want all records from the primary table even if there's no match in the related table. For example, getting all customers even if they haven't placed an order yet.
What is the difference between JOIN and UNION in MySQL?
JOIN combines columns from multiple tables horizontally. UNION stacks rows from multiple queries vertically. JOIN is for related data, UNION is for merging similar result sets.