välisvõtmete
Välisvõtmed, or foreign keys, are a fundamental concept in relational database management. A foreign key is a column or a set of columns in one table that uniquely identifies a row of another table. Its primary purpose is to establish and enforce a link between two tables, ensuring referential integrity. When a foreign key constraint is defined, the values in the foreign key column(s) must match values in the primary key column(s) of the referenced table, or they must be null. This prevents orphaned records, where a record in one table refers to a non-existent record in another. For instance, in a database with "Orders" and "Customers" tables, a "CustomerID" column in the "Orders" table would likely be a foreign key referencing the "CustomerID" primary key in the "Customers" table. This ensures that every order is associated with a valid customer. Database systems use foreign keys to manage relationships between data, enabling efficient querying and preventing data inconsistencies.