Thus far, we've learned about the syntax and use of constraints using simple test tables. In this section, we take what we've learned and apply it to creating new tables and constraints in our Companylink
database.
Our Companylink
tables have been designed as a fully relational model. Each table has an ID column that relates to another table, although no constraints exist. We can take what we've learned thus far and add constraints to our Companylink
tables. Our model is centered on our employee
table, so we can start there.
In this example, we add a primary key to our employee
table:
Our existing values in the employee_id
column meet the requirements of a primary key—they are unique and no NULLs exist in the column. Next, we add a foreign key to the address
table that relates to the employee
table.
Once this relationship is established, we can no longer insert values into the address
table...