[ad_1]
Key fields in a database uniquely identify entries and enforce integrity across tables. They must be unique, unalterable, and required. Simple and compound keys are used, with composite keys reducing the chance of multiple records. Primary keys are used in original tables, foreign keys link tables together.
A key field is a column or combination of columns in a database that uniquely identifies the specific entry in question. These fields are used to identify and enforce integrity across multiple tables in a database. These fields are of two general types: simple and compound keys, depending on the number of columns marked as a key field. When used in its original table, this field is known as the “primary” key; when used in another table as a method of linking tables together, it is known as a “foreign” key.
To be useful as a key field, a key candidate must be unique, unalterable, and required. Uniqueness is simple to understand; means that no other entry in the database can have a key value that matches any other entry. Unalterable means that the information in the key value is fixed and immutable, never changing over time. Required means that for no entry in the database the key value can be left blank. For example, an optional category such as race or nationality cannot be used as a key field in an employee database because some employees may not be willing to provide this information.
Choosing appropriate key fields allows the database to maintain its integrity while remaining consistent across tables. For example, if a database lists employee records, a typical entry might contain the employee’s first name, last name, date of birth, and Social Security or ID number. The obvious choice for a key field is the Social Security or employee ID number; both of these would meet the requirements of unique, unalterable, and required. When attempting to search the database for a specific employee record, entering the number does not immediately return more than one single employee record. If you use the employee’s last name as the key field, multiple employee records may be found, because more than one employee can share a last name.
One way to reduce the chances of accidentally choosing a key field that has the potential to return multiple records is to use a composite key. Unlike a simple key, which uses only one column, a compound key uses a combination of multiple columns to represent key fields. For example, using a combination of an employee’s first name, last name, and date of birth as a key would drastically reduce, but not completely eliminate, the chances of violating the uniqueness requirement. This provides a solution when a good simple key is not readily available.
[ad_2]