Book a Demo

Author Topic: Import Database Schema and Foreign Keys  (Read 4491 times)

RajuJoseph

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Import Database Schema and Foreign Keys
« on: June 08, 2018, 02:19:05 pm »
We are currently using Sparx EA version 12.1. We have reverse engineered our SQL Server 2008 database to create a datamodel.

We have created a few foreign keys that do not exist in the physical model. The project is saved and everything looks good.

Now after a new release, we did the Import DB Schema again. But this time, the foreign keys we had created went away after the import. This could be due to EA synchronizing the foreign keys also.

Is there a way for us to preserve the foreign keys which exists in the model? Can we configure EA to not synchronize foreign keys?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Import Database Schema and Foreign Keys
« Reply #1 on: June 08, 2018, 03:53:59 pm »
I don't think so.

What you are doing seems a bit strange to me.
By reverse engineering you create a model that is 100% the same as your physical database.
By adding FK relations that aren't there you are making a model that is no longer representing the physical thing.
What is the sense of having a physical model when it doesn't represent the actual physical thing, but rather the physical thing and then some other stuff that isn't really there.


I think you should either:
- forward engineer the foreign keys so they are in the database as well and will be there when you reverse engineer
- create these "foreign key who aren't really foreign keys because they don't exist in the database" relations on a logical model rather then on a technical model.

Geert

RajuJoseph

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: Import Database Schema and Foreign Keys
« Reply #2 on: June 09, 2018, 09:10:08 pm »
I completely agree with what you have said. Unfortunately the system is quite old (10+ years) and those who created the physical tables, for some reason, decided not to define foreign keys.

We do not have the luxury of forward engineering the changes at this point. I was wondering if Sparx had something which prevents overwriting the relationships already defined in the model or add only those tables from the database that are new/modified.
« Last Edit: June 09, 2018, 09:12:10 pm by RajuJoseph »

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: Import Database Schema and Foreign Keys
« Reply #3 on: June 11, 2018, 12:37:36 pm »
I completely agree with what you have said. Unfortunately the system is quite old (10+ years) and those who created the physical tables, for some reason, decided not to define foreign keys.

We do not have the luxury of forward engineering the changes at this point. I was wondering if Sparx had something which prevents overwriting the relationships already defined in the model or add only those tables from the database that are new/modified.
Hi Raju,

We have a similar problem (and in this case, the third party software is pretty current).  From what we can see, there are over 2000 tables without a single Foreign Key Constraint!

Now to your question.  As Geert says, you are (by reverse engineering) creating a physical model.  Consequently, every time you reverse engineer, what you should end up with is a "copy" of the physical DB.  If you want to create things that DON'T exist in the physical model, then you either have to be able to forward engineer the changes to the physical DB (and thus make the reality the same as the updated model) or you have to change something other than the physical model - because otherwise you can't update the physical model.

About a decade ago, we came to the conclusion that there are TWO models at the physical level.  The Design Model (what we want to see in the DB) and the Implementation Model (what is actually in the DB).  The Design Model is only ever forward engineered and the Implementation Model is only ever reverse engineered.  The two models can (because they are at the same level of abstraction) can be compared and contrasted.

The process we generally use to create the Design Model (where there is only an implementation model), is to export the Implementation Model and re-import changing the GUIDs and tracing back to the implementation model. We can, therefore, make changes (such as you intend) to the design model and that's what we use in normal circumstances.

In any event, since (as I understand it) you can't change the physical DB, you aren't creating Foreign Key Constraints in the implementation model, but merely documenting dependencies between the columns in various tables.  You may "get away with" creating your relationships as Dependencies which might NOT be affected by reverse engineering.

HTH,
Paolo
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!