At this point we want to place our schema definitions into the first text box on this page.
Because it's what I'm using, I'll walk through the process for MySqlWorkbench, but of course, any other system works perfeclty fine.
Via the top SERVER -> Data Export, select the tables that you want to check, and choose "dump structure only".
This will hand back a .sql file with the necessary information, the contents of which you can paste into the box.
CREATE TABLE departments (
dept_no CHAR(4) NOT NULL,
dept_name VARCHAR(40) NOT NULL );
CREATE TABLE dept_manager (
emp_no INT NOT NULL,
dept_no CHAR(4) NOT NULL,
from_date DATE NOT NULL,
to_date DATE NOT NULL );
Now let's reconfigure the setting at the top of this page to check for candidate keys of size 2 (still allowing nulls in primary key checking).
Running this new script, you should see all the same results as before, and more. I encourage you to skim through all of the results, but one of
the newly produced ones is included below.
This result says that together, to_date and from_date exactly specify a dept_manager. While a bit trickier to verify than emp_no, closely analyzing the table does reveal this to be true.
Note that while emp_no and to_date, do exactly a dept_manager, this is not reported as a primary key. This is because primary keys are defined to be minimal, meaning that if emp_no alone is a primary key, then emp_no + to_date is not.
This concludes the demo. You are ready to go out and try the tool with your own data!The rule finder makes use of SQL queries to check for primary and foreign keys. For example, or each primary key k, we generate two SQL queries, front(k) and back(k), whose difference indicates primary key violations.
For example, if our attributes are name and age and k = name, then front(k) and back(k) are:
SELECT * FROM persons AS A, persons AS B WHERE A.name = B.name
SELECT * FROM persons AS A, persons AS B WHERE A.name = B.name AND A.age = B.age