Better Data Modeling: Finding Missing Unique Keys in Oracle #SQLDevModeler
One of the best practices I recommend is to always define unique business keys for every entity (or table) in a model.
It is the only way to really understand what the data in that object represents.
So what do you do when you inherit someone else’s model with hundreds of tables and few (if any) unique keys to be found?
After you reverse engineer it into SDDM (SQL Developer Data Modeler), you could go through the model table by table and look at the properties.
Or, you could look at all the diagrams to look for the the little U’s indicating a column is part of a unique key constraint (assuming there are any diagrams to look at).
Or you could create a Custom Design Rule that checks for you.
So how do you write a design rule that will list all tables with no UKs on them?
Open your design, the go to Tools -> Design Rules -> Custom Rules.
- Hit the green Plus sign to add a new rule.
- Give it a name (like Missing UKs),
- Select Table for the object type,
- Mozilla Rhino for the Engine,
- Warning for the type, and
- Select table as the variable
- Past in this code:
Hit Save, then Apply.
The result will be a list of all the tables in your design that do not have any Unique Key Constraints defined.
Now the real work begins – fixing those tables! As you work your way through the model adding the new business keys, you can keep using this report to see which ones you have left, and make sure you don’t miss any.
Get to it my friends!
The Oracle Data Warrior