Add Database Relationships

Add Foreign Key Constraint

Adding foreign key constraints allows the system to visualize relationships between your tables. Foreign keys also enforce referential integrity in your database.

How to Add Relationships
  1. Select the "From Table" (the table that contains the foreign key)
  2. Select the "From Column" (the column that will be the foreign key)
  3. Select the "To Table" (the table being referenced, usually containing the primary key)
  4. Select the "To Column" (the column being referenced, usually the primary key)
  5. Click "Add Relationship" to create the foreign key constraint

Example: If you have a users table with an id column, and a posts table with a user_id column, you would set:

  • From Table: posts
  • From Column: user_id
  • To Table: users
  • To Column: id
Important: Before adding a foreign key constraint, ensure that:
  • The data types of both columns match (e.g., both are INT)
  • The referenced column is a PRIMARY KEY or has a UNIQUE constraint
  • All values in the foreign key column already exist in the referenced column