Primary Key
A primary key is a column or a set of columns in a database table that uniquely identifies each row. It must contain a unique value for each record and cannot have any null values, ensuring data integrity and preventing duplicate rows. Primary keys are crucial for establishing relationships between tables and speeding up data retrieval.
Characteristics of a primary key
Uniqueness: Each value in the primary key column(s) must be unique to distinguish one record from another.
No null values: A primary key cannot be empty or null, ensuring every record has a value.
Single per table: A table can have only one primary key, although that key can be made up of multiple columns (a composite primary key).
Relational importance: It is used to establish relationships between different tables in a relational database, often by being referenced by a foreign key in another table.
Performance: Databases often create an index on the primary key, which allows for faster lookups, updates, and deletions of specific records.