Teach Any Computer Science Class
We have put together a full GCSE Computer Science curriculum that will give you all the teaching materials you need to teach any topic.
Whether you're a brand new Computer Science teacher, or you've been teaching ICT for years, our resources will save you hours and hours of lesson preparation every single week.View the Lessons →
A primary key, also known as the primary keyword, is a key in a relational database that is specific for each record. It is a unique attribute like a driver’s license number, telephone number with area code or vehicle identification number (VIN). A relational database must have only one primary key. Primary keys are usually displayed as columns in relational database tables.
The choice of a primary key in a relational database is often based on the preference of the administrator. The primary key for a given database can possibly change when the specific needs of the users change. For example, the people in a town might be uniquely identified based on their driver’s license numbers in one application, but in another situation, it might be more appropriate to identify them based on their telephone numbers.
A primary key is a distinct identifier for a database record. One of the fields is typically assigned as the primary key once a table is created. While the primary key is often a number, a text field or other data type may also be assigned as a primary key. For example, if a database contains definitions of computer terms, it would be logical that each term is only listed once in the database. By defining the “Term” field as the primary key, it would guarantee that no term is listed more than once in the database.
While a table’s primary key is usually assigned to a specific field, it can also be composed of multiple values. For example, a database of news articles can utilise both the title and date fields to distinguish each entry. By combining the “Title” and “Date” fields as the primary key, it would warrant that no entries have the same title on the same day.
If several fields in a table cannot have identical values, most database management system (DBMS) also let fields to be marked as “Unique.” This is like setting a field as the primary key but is not the same thing. The primary key also acts as an indicator to the record and offers a simple way for the DBMS to search, sort and access the records. It also helps connect records across multiple tables. Therefore, while multiple fields within a table can be defined as “Unique,” each table can only have one primary key. The primary key field must also be established for each record and cannot be null. After all, an undefined identifier is not very useful.
A primary key is a special relational database table column or a combination of columns selected to uniquely identify all table records.
Main Features of Primary Key
- It must contain a unique value for each row of data.
- It cannot contain null values.
A primary key is either an existing table column or a column that is specifically made by the database according to a defined sequence.
The primary key concept is important to an efficient relational database. Relational databases would not work without primary key and closely related foreign key concepts.
Almost everyone deals with primary keys frequently but unknowingly in everyday life. For example, students are routinely assigned unique identification (ID) numbers and citizens of a country have unique government-assigned IDs.
For example, a database must contain all the data stored by a commercial bank. The best option is to create a separate primary key in a new column named CUSTOMER_ID. The database automatically generates a unique number each time a customer is added, ensuring unique identification. As this key is created, the column is assigned as the primary key within the SQL script that creates the table and all null values are automatically rejected.