I will be using phpMyAdmin (version 22.214.171.124) for this purpose, for the purpose of this example, we will create two simple database tables. They are not well designed, but will demonstrate the power of foreign keys!
employee: a table of company employees where each member is assigned a unique ID
borrowed: a table of borrowed books. Every record will reference a borrower’s employee ID.
We will define a foreign key relationship between the employee’s ID in both tables.
CREATE TABLE employee (
id smallint(5) unsigned NOT NULL,
PRIMARY KEY (id),
KEY idx_lastname (lastname) ) ENGINE=InnoDB;
CREATE TABLE borrowed (
ref int(10) unsigned NOT NULL auto_increment,
employeeid smallint(5) unsigned NOT NULL,
PRIMARY KEY (ref) ) ENGINE=InnoDB;
We can now specify our foreign key (this could be handled in the CREATE TABLE statement, but it is shown separately here):
ALTER TABLE borrowed ADD CONSTRAINT FK_borrowed FOREIGN KEY (employeeid) REFERENCES employee(id) ON UPDATE CASCADE ON DELETE CASCADE;
Now our sample database is ready let’s export it as PDF with foreign keys and internal relationships
1) Select your database from LHS navigation from, then select the “operations” tab from RHS tab menu list
2) On the “operations” tab click the link “Edit or export relational schema”, will be present at LHS page bottom
3) Enter the “page name” and select the checkboxes for internal Relations and Foreign Keys, click the “Go” button
4) On this page you can change the page layout (portrait vs landscape) and paper size (default selected option is A4), change these values as per your requirement and click the “Go” button, save the generated PDF
page displaying linking between the employee table and borrowed table