Junior — Middle
Is a primary key in an SQL table also an index for fast data retrieval?
sobes.tech AI
Answer from AI
Yes, a primary key (PRIMARY KEY) in an SQL table automatically creates a unique index. This allows the database to quickly find rows by the primary key value, ensuring efficient search and maintaining the uniqueness of records.
For example, if you have a users table with an id field as the primary key, then when querying by id, the DBMS uses the index to quickly find the needed record without scanning the entire table.