Imagine a phone book organized as a B-tree index. What is the main reason this structure helps find a name faster than scanning every page?
Think about how you find a word in a dictionary without reading every page.
A B-tree index splits data into smaller parts, letting the search jump directly to the relevant section, avoiding a full scan.
Given a table Employees with a B-tree index on LastName, what rows will this query return?
SELECT * FROM Employees WHERE LastName = 'Smith';
CREATE TABLE Employees (ID INT, FirstName VARCHAR(50), LastName VARCHAR(50)); CREATE INDEX idx_lastname ON Employees(LastName); -- Assume data includes multiple 'Smith' entries
Indexes help find matching rows faster but do not change which rows are returned.
The index helps the database quickly locate all rows with LastName 'Smith', returning all matching rows.
Choose the correct SQL command to create a B-tree index on the email column of the Users table.
Standard SQL uses a simple syntax for creating indexes; specifying B-tree is often default.
Option D is the standard syntax. Options A, B, and D are invalid or non-standard in most SQL databases.
Consider a B-tree index on a column that has only three distinct values repeated many times. Why might this index not improve query speed much?
Think about how useful an index is when many rows share the same value.
When many rows share the same value, the index points to large groups, making it less efficient than scanning.
What error will this SQL statement produce?
CREATE INDEX idx_wrong ON Users(email,);
Check the syntax carefully, especially commas in lists.
The trailing comma after 'email' causes a syntax error in SQL.