VistaDB 6
VistaDB / Developer's Guide / How To Perform Common Tasks / How To - Build and Visualize Foreign Key References
In This Topic
    How To - Build and Visualize Foreign Key References
    In This Topic
    Foreign Keys (FKs) are one of the primary mechanisms in relational databases for ensuring your data is kept in a known good state.

    FKs are used most often to ensure that when a row in one table is updated that related rows in another table are also updated.


    Table: Employees
    EmployeeID - Primary Key

    Table: Timesheets
    TimesheetID - Primary Key
    EmployeeID - The employee for this timesheet

    If you want all employee timesheets to be deleted when the employee record is deleted you would go to the Timesheets table and add a Foreign Key.

    This will then result in a Foreign Key on the Timesheet table that will enforce that all rows track what happens to Employee records.

    The way to read this information is that the Primary Table Employees.EmployeeID Column will check with the Timesheets table whenever an update or delete is performed. In this case both operations will result in the same operation for matching entries in the Timesheets table.

    If an EmployeeID is changed the Timesheet entries for that column will also be updated.
    If an EmployeeID is deleted the Timesheet entries will be removed as well.

    See Also