Junior — Middle
Does a primary key in an SQL database automatically create an index to speed up searches?
sobes.tech AI
Answer from AI
Yes, in most database management systems (DBMS), when declaring a primary key, an index is automatically created on that column or set of columns. This is done to speed up search operations, as the primary key guarantees uniqueness and is often used for quick data access.
An index allows the DBMS to efficiently find rows by the primary key value without needing to scan the entire table.
For example, in SQL:
CREATE TABLE Users (
id INT PRIMARY KEY,
name VARCHAR(100)
);
In this case, a unique index will be automatically created on the id column.