Skip to Content
avatar image
Former Member

Naming template for Key (PK, UK)

Where can I find the rules on how PD 16.5 generates the text it puts in the Name AND Code columns for a Key on a Table. Key could be Primary or Unique.

Right now it is generating a value such as key_1, key_2. I would like it to use the same value as used by ConstraintName, for which I have a rule defined in the DBMS Resource file to generate the value such as PK_tablename, UK_tablename_seqnbr.

Having the Name and Code columns as Key_1 is not impacting the DDL being generated, but when merging the Dev model to Production model, it is getting difficult to identify which changes to merge.

I want to do a similar thing for Name and Code column for References (i.e Relationships). Would like to put the same value as in Constraint name in this case too.

I am using Oracle 10 or 11 databases.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Oct 23, 2015 at 05:23 PM

    It' very easy to rename object name in script.

    In your case, you can modify the following code:

    set tables=model.tables

    for each t in tables

      set keys= t.keys

      for each k in keys

         output k.name

         output k.code

         output k.constraintName

         output k.name & " is primary key " & k.primary

      next

    next

    set references=model.references

    for each ref in references

         output ref.name

         output ref.code

    next

    You can reset key name or reference name using statement like

       k.name=" abc"

       ref.code=" ref_code"

    To execute the code, open your model, go to Tools->Execute Commands->Edit /Run Script.

    For more information, go to Help->Meta objects Help. Search for an object name.

    Add comment
    10|10000 characters needed characters exceeded

    • Hello Navin

      You need to have event handlers to take control of the object names, leave the codes to work themselves out. I've worked some code you can use to start with, it'll still need some work - perhaps put code into a global script, so it can be referenced in a custom model check instead.

      The initialise event could look like this:

      Function %Initialize%(obj)

         ' Implement your initialization on <obj> here

         ' and return True in case of success

         Dim count

         Count = 0

         Dim newName

         if obj.Primary then ' this is the PK

            newName = "PK_" & obj.Table.Name

            ' need code here to check if this name already exists

            if not obj.Name = newName then obj.Name = newName

            %Initialize% = True

          

         else

            count = count + 1

            newName = "UK_" & obj.Table.Name & "_" & count

            ' need code here to check if this name already exists

            if not obj.Name = newName then obj.Name = newName

            %Initialize% = True

          

          end if

      End Function

      The Validate event could look like this:

      Function %Validate%(obj, ByRef message)

         ' Implement your object validation rule on <parent> here

         ' and return True in case of success, False otherwise with a message

         Dim count

         Count = 0

         DIM newName

         if obj.Primary then ' this is the PK

            newName = "PK_" & obj.Table.Name


            ' need code here to check if this name already exists


            if not obj.Name = newName then obj.Name = newName

            %Validate% = True

         else

            count = count + 1

            newName = "UK_" & obj.Table.Name & "_" & count


            ' need code here to check if this name already exists


            if not obj.Name = newName then obj.Name = newName

            %Validate% = True

         end if

      End Function

  • Nov 02, 2015 at 01:51 PM

    http://scn.sap.com/thread/3443769

    HTH

    DJ

    Add comment
    10|10000 characters needed characters exceeded

  • Nov 06, 2015 at 02:21 PM

    Navin, I don't understand your issue when you say "when merging the Dev model to Production model" - if you compare two versions of the same model, won't the object GUIDs be the same, so the comparison matches them up?

    Are you reverse-engineering production in order to compare it? Are the key names amended after generating the DDL? If so, PD will have a problem matching them up, and there's little you can dio about that unless you make the keys in the model match those in the database.

    When you generate DDL or create/update a database, do you save a PDM archive file? If you don't, you should; if you do, then you can compare the development PDM against the archive file, the GUIDs will match and you'll get fewer (maybe zero) false differences.

    Add comment
    10|10000 characters needed characters exceeded

    • The metaclass you need is already in the profile - it's 'Key'. Right-click it and select the option to add an event handler. This screen shot shows that SQL Server 2008 already has an event handler, which could be amended to manage the object names.

      Make sure you're working on a copy of the definition, or embed it in your model first (by changing the definition to the same one, and clicking on 'embed resource in model' before clicking OK:

      If the database definition is embedded in the model, it'll be included in any models generated from it, though it won't be available for any new models unless you also save it in a file in the path that PD looks in for such files.