Välisvõtmed
Välisvõtmed, often translated as foreign keys, are a fundamental concept in relational database design. They are a field or a set of fields in one table that refers to the primary key in another table. The purpose of a välisvõti is to establish and enforce a link between two tables. This link ensures referential integrity, meaning that the relationships between data in different tables remain consistent. For example, if you have a table of customers and a table of orders, the välisvõti in the orders table might refer to the customer ID in the customers table. This prevents an order from being associated with a non-existent customer. When a välisvõti is defined, the database system typically enforces rules such as preventing the deletion of a record in the referenced table if there are related records in the referencing table, or it can be configured to cascade deletions or updates. Välisvõtmed are crucial for organizing data logically, preventing data redundancy, and maintaining the accuracy and reliability of databases. They are a core component of the structure that allows for complex queries and data retrieval across multiple related entities.