• About Heli

HeliFromFinland

~ Heli's thoughts on Database Designing, Oracle SQL Developer Data Modeler, User Groups etc.

HeliFromFinland

Category Archives: Database design

General issues about database design

My Books

29 Friday Jul 2016

Posted by Helifromfinland in Data Modeler, Database design, Oracle

≈ Leave a comment

So far I have written two books, the first one by myself and the second one with good friends. If you are interested check from Amazon:

http://www.amazon.com/Oracle-Developer-Modeler-Database-Mastery/dp/0071850090

http://www.amazon.com/Real-World-SQL-PL-Experts/dp/1259640973/

Recognizion for a DB Designer, FINALLY!

06 Thursday Aug 2015

Posted by Helifromfinland in Database design

≈ 1 Comment

Finally the work of a database designer will be recognized! Oracle has announced the Oracle Database Developer Choice Awards nomination and one of the categories makes me very, very happy: DB Design.

It has been too long that the work of a database designer has been ignored. If you know a great database designer, somebody who has been speaking up for the importance of database design even in bad times or somebody who has been helping you with database designing, go and nominate him/her NOW: https://community.oracle.com/community/database/awards

Thank you Oracle, for understanding the importance of database designing and promoting it!

How to define a PK using Data Modeler?

30 Thursday Jul 2015

Posted by Helifromfinland in Data Modeler, Database design

≈ 7 Comments

Primary Key (PK) identifies uniquely each row in a table. There can never be two tuples with same values in PK.

There are two ways of defining a PK: a natural key or a surrogate key. I would say that if you can find a natural key that is always better. But it is not always possible and therefore we can also use surrogate PKs. Surrogates are usually sequence numbers that has no meaning to the business people, the end users.

Let’s have an example of an entity for all the users in a company.

PK1

PK2

1. Defining a natural PK

What I want is that there will never be more than one user with the same username. If this means that there can NEVER be two with the same username, I would define the PK like this:

PK3

You can see the PK definition from Unique Identifiers tab:

PK4

And by clicking the Properties button (XYZ and a pen) you can see and edit the properties for this unique identifier.

You can for instance change the name

PK5

Or see what attributes or relationships are involved in this PK. You can add or remove attributes or relationships to/from the PK using the arrows pointing to right and left. And you can change the order of the PK elements using the arrows pointing up and down.

PK6

If the requirement would be that there can never be two users at the same time with a same valid username I might think a bit. If I am sure that a pair (Username, Valid) would be enough as a PK, it means that I can only have max two users with the same Username: one with Valid=true and another one with Valid=false, I could define that as the PK, but what happens when the second one needs to be disabled eg. Valid changed to false? Then I would have two tuples with same values in Username and Valid, that would not work because that is my PK. So having a PK with just Username and Valid would not be quite smart. I could also use Created date in PK but would that be smart? No. Having a PK (Username, Valid, Created) would help me to disable a username even though there is already another of the same Username disabled or adding the third user with the same Username but it would not guarantee that only one user would have that Username at a point of time. And that was exactly what the requirement was.

I could add BeginDate and EndDate as attributes:

PK7

But that would not help me because I could not use those attributes in the PK because I should be checking that the two rows are not valid at the same time, eg. comparing the BeginDates and EndDates for all rows having the same Username. Of cause I could check those attributes using PL/SQL and check that only one row is valid at a time but that is not a PK.

No wonder many people end up to the conclusion that the requirement means that there can NEVER be two users with the same Username 🙂 Then the PK (Username) would be sufficient.

But what if the requirement really is that there cannot be more than one at the same point of time? Then I would use surrogate as the PK and use PL/SQL (trigger) for checking the rest.

2. Defining a surrogate PK

There are two ways to define a surrogate PK: manually or automatically.

If I want to create it manually, I simply define an attribute for it and define it as the PK. My recommendation is that if this is the way you want to work, start by defining a Domain for surrogates and always use that when defining a surrogate PK manually. Otherwise defining a surrogate PK manually is done just like I explained earlier on Defining a natural PK.

You can also define a surrogate PK automatically. In entity properties enable Create Surrogate Key and when you engineer to relational model, this surrogate key and the surrogate column are created automatically.

PK8

If using surrogate keys is the preferred way of working for you, you might consider enabling that property so that the default would be Create Surrogate Key enabled.

PK9

Remember that you can define the naming standard for the surrogate key and the column created in Design Properties (right-click on the Design name and select Properties):

PK10

This was a quick look to PKs. A natural key is always the best and being able to define one you must know the requirements and understand them. If a natural key does not work, then a surrogate key is an option.

Oracle SQL Developer Data Modeler for Database Design Mastery available in EMEA!

12 Friday Jun 2015

Posted by Helifromfinland in Data Modeler, Database design, General

≈ 6 Comments

My book is finally available in EMEA:

Amazon
http://www.amazon.co.uk/Oracle-Developer-Modeler-Database-Mastery/dp/0071850090/ref=sr_1_1?s=books&ie=UTF8&qid=1434007533&sr=1-1&keywords=9780071850094

M-H Education EMEA
http://www.mheducation.co.uk/9780071850094-emea-oracle-sql-developer-data-modeler-for-database-design-mastery

Journaling tables in Data Modeler 4.1

22 Friday May 2015

Posted by Helifromfinland in Data Modeler, Database design

≈ 4 Comments

Creating journaling tables is very easy with Oracle SQL Developer Data Modeler.

1. If you have not done so yet copy the file dr_custom_scripts.xml from datamodeler\datamodeler\types\ to your Default System Types Directory. Now you will have the journaling script ready for Data Modeler to use.

If you do not remember where your Default System Types Directory is, go and check from Preferences:

Journaling_05

2. If you want to test the script or change it, go to Table DDL Transformations:

Journaling2

Select the script Journal tables. Test  by pressing the Test button and Save any changes by pressing the Save.

Journaling3

3. Generate the journal tables

Start by selecting Export, DDL File from File Menu.

Journaling4

Select the script and tables you want to create the journal table in Include Table DDL Scripts tab:

Journaling5

Check the SQL generated:

Journaling6

If you are happy with it just save the DDL file.

Creating journaling tables could not be easier than this 🙂

Finding an older version of the design from Subversion

13 Wednesday May 2015

Posted by Helifromfinland in Data Modeler, Database design

≈ 2 Comments

You might want to see an older version of your database design. Maybe to get the DDLs to create a database of that version or maybe to compare to another version of the database design or the data dictionary.

How to get that version from Subversion?

First select Team, Check Out…

v11_1

Enable Use Revision and press Select Revisions…

v11_2

Select the revision that matches your version and press OK.

Open the design from the working directory.

v11_3

Maybe you would like to get the DDLs to create a database of version 1.1?

Select File, Export, DDL File.

v11_4

Select the RDBMS Site wanted (for the SQL syntax).

v11_5

Select the elements you want in the DDL.

v11_6

See the SQL and if you like it press Save.

v11_7

Run the saved SQL script to your database.

Now you have a design of version 1.1 and a database with version 1.1 structures.

Certified Data Vault 2.0 Practitioner

10 Tuesday Jun 2014

Posted by Helifromfinland in Database design

≈ Leave a comment

Today I passed the certification test for Data Vault 2.0 professionals organised by Daniel Linstedt. I am so proud!

Is phone number an entity or an attribute?

24 Thursday Apr 2014

Posted by Helifromfinland in Database design

≈ Leave a comment

Short answer: it depends.

At first I would say it is an attribute but…

if you need to:

– have many different kinds of phone numbers and you cannot say how many (0-n) and maybe the type of the number varies in different cases (home number for a person, office number for a company, fax number for both) and maybe the types for phone number do not remain the same

– have history data for the numbers (which number was valid at certain time)

or something similar.

You might actually have an entity in hands.

Or if you know there might be max four phone numbers but two of them are mandatory, we come back to the conclusion it is an attribute.

So it depends on the requirements weather phone number is an attribute or an entity.

Is social security number a good primary key?

18 Friday Apr 2014

Posted by Helifromfinland in Database design

≈ Leave a comment

Short answer: no.

Why? Well I can give you at least 10 reasons but just to start with….

– social security number (SSN) is not unique, at least not world wide

– it does not identify a person (for instance my father has two social security numbers, exceptional but possible)

– it can be changed: you come to another country and are given a temporary SSN. You get the citizenship and get the real one. Changed.  There are plenty of cases when the SSN is changed.

– it is not something you can define yourself, it comes from another system and is controlled by other organization and their rules. What if they change the rules? Do not have PKs from another system’s data (history data etc)

– it is many times defined as sensitive data. It will be quit a job to get reduction or masking done to all the columns in child tables.

etc.

I prefer natural primary keys over surrogates but social security number is not one. So please save your time and energy and do not define SSN as a primary key.

Newer posts →

Subscribe

  • Entries (RSS)
  • Comments (RSS)

Archives

  • October 2022
  • October 2021
  • April 2020
  • October 2019
  • October 2018
  • June 2018
  • December 2017
  • October 2017
  • September 2017
  • July 2017
  • April 2017
  • March 2017
  • February 2017
  • January 2017
  • December 2016
  • November 2016
  • October 2016
  • September 2016
  • August 2016
  • July 2016
  • June 2016
  • May 2016
  • April 2016
  • March 2016
  • February 2016
  • December 2015
  • November 2015
  • October 2015
  • September 2015
  • August 2015
  • July 2015
  • June 2015
  • May 2015
  • April 2015
  • March 2015
  • January 2015
  • December 2014
  • November 2014
  • October 2014
  • September 2014
  • August 2014
  • June 2014
  • May 2014
  • April 2014
  • January 2014
  • December 2013
  • November 2013

Categories

  • Data Modeler
  • Database design
  • Events
  • General
  • Oracle
  • SQL Developer

Meta

  • Register
  • Log in

Blog at WordPress.com.

Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy
  • Follow Following
    • HeliFromFinland
    • Join 49 other followers
    • Already have a WordPress.com account? Log in now.
    • HeliFromFinland
    • Customize
    • Follow Following
    • Sign up
    • Log in
    • Report this content
    • View site in Reader
    • Manage subscriptions
    • Collapse this bar
 

Loading Comments...