Resources | Subject Notes | Computer Science | Lesson Plan
In database design, a primary key is a crucial concept. It's a special column (or set of columns) in a table that uniquely identifies each record (row) within that table.
The primary key serves several important purposes:
A good primary key should meet the following criteria:
Consider a table called Students. This table stores information about students in a school.
Student ID | First Name | Last Name | Grade |
---|---|---|---|
101 | Alice | Smith | 10 |
102 | Bob | Johnson | 11 |
103 | Charlie | Brown | 10 |
In this Students table, the Student ID is a suitable primary key. It fulfills all the criteria for a primary key: it is unique, not null, and should ideally not change.
Understanding primary keys is fundamental to database design. They ensure data integrity and allow for efficient data management.