Book a Demo

Author Topic: Make an attribute a PK in target table of a transformation to DDL  (Read 5493 times)

asantoni

  • EA Novice
  • *
  • Posts: 1
  • Karma: +0/-0
    • View Profile
Hi there,

I am using a transform from a class diagram model to a DDL model and would like one of the attributes in the class element to be used as the Primary Key of the target table in the transformed model.
Is there a way to do that?
« Last Edit: March 05, 2021, 12:52:48 am by asantoni »

ea1020

  • EA User
  • **
  • Posts: 21
  • Karma: +0/-0
    • View Profile
Re: Make an attribute a PK in target table of a transformation to DDL
« Reply #1 on: March 05, 2021, 02:44:17 pm »
I had a similar question for support a few weeks ago.  If you right-click on the Attribute in the class diagram, select Properties, then you will see a property/attribute called IsID under the Advanced header.  So I thought that the transform process should use that, instead of creating a standard <ClassName>ID column for the Primary key.  EA support people disagreed, and thought it was fine for EA to ignore IsID.  I'm not sure what the point is of having the IsID property/attribute....


So you will need to alter the Transform Templates yourself, for the DDL language.  You will need to alter:
- Attribute: add code to suppress creating the column in this template, if the attribute is to be used as the PK
- Class:  add code to skip the standard Transform Template code to create the standard PK column (<ClassName>ID) and to instead create a PK based on your requirements
- Connection:  If the PK column has changed, you also need to alter all the Transform Template code in this template that creates a column for the FK column in a table that refers to the table for which you altered the PK column, plus alter the creation of the FK constraint.

I did the above, but I only altered Connection as far as was necessary for my case.  For example, I only wanted to alter the PK for tables that would be used as lookup/reference/type tables; e.g. a Status table, and then other tables would have a "StatusCode" column and an FK to Status.StatusCode.
Relationships such as many-to-many, or inherited classes (Generalization) are not yet handled.

I wrote the Transform Template alterations so that you must add up to two Tagged Values on the class:
  • one to specify the column to be used as the PK
  • one to specify the data type for the column to be used as the PK (Yes it would have been smarter to somehow find the required Attribute and read the datatype value, but I did not quickly see a way to do this in the documentation that EA provides.  If you find a better way, please let me know.

Will the above be sufficient for you?  I can paste in the code if it is.  I will ask in another post where this type of code should be posted, to help the community.

Dale Fox

Richard Freggi

  • EA User
  • **
  • Posts: 498
  • Karma: +18/-7
    • View Profile
Re: Make an attribute a PK in target table of a transformation to DDL
« Reply #2 on: May 26, 2026, 01:31:40 pm »
Hello reviving this post. I have the same issue to trnasform a class diagram with [id] property and Identifier datatype into a logical ERD data model using the DDL transformation.  I googled, ChatGPTed and tried different ways, and could not find clear instructions in the Sparx manuals. 
I need the [id] property / Identifier datatype to be converted to PK, then migrated correctly to FK in related entities.  All logical level so datatypes don't matter.

If someone can provide the transformation scripts and a detailed guide on how to create the transformation template please help!  Thank you!

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13520
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Make an attribute a PK in target table of a transformation to DDL
« Reply #3 on: May 26, 2026, 07:13:07 pm »
Hi Richard,

I'm not convinced the transform templates are capable of correctly transforming a logical model into a relational database model.
I think there is too much, and too complex logic involved to be able to solve that with the template approach.

I wrote an add-in for a specific client to automate this transformation https://bellekens.com/ea-database-transformer/
This add-in is unlikely to be useful for anyone else, but the logic involved in transforming an LDM to a DB model is not simple.

There are a lot of complexities to think about
- flattening inheritance
- datatype transformation
- naming conventions
- converting associations into FK's (especially many-to-many associations)
- ...

Geert

Richard Freggi

  • EA User
  • **
  • Posts: 498
  • Karma: +18/-7
    • View Profile
Re: Make an attribute a PK in target table of a transformation to DDL
« Reply #4 on: May 27, 2026, 08:59:03 am »
Hello Geert good to hear from you! Agree with what you said but the goal is to change the notation of a UML logical model (the IATA AIDM I mentioned in my other post) into the same logical model in IE notation with PKs, migrated FKs and cardinalities.  This .makes it easier to extend the logical model to support our project architecture.  So no talk of transforming to physical level, I just need the transformation scripts to do the job and explanation on how to use them - cheers!