Generating DDL file

On another forum I have posted issues that I am having with updating models with the database while this is looked at, I think the process may be too heavy for couple of table updates. Is there an API for generating DDL scripts? I would like to create a macro that by right clicking gives me the option to write the DDL statements and the content related packages.

The scenario would be to
Open Text Stream
Write the current entity DDL (create table, comments, constraints)
Write the associated package (Heavy user of naming conventions)

If I need to write the whole statement piece by piece, I will do it but API would be better.

Hi Hazi,

please see this article:

Of course, feel free to modify it to add there code of your associated packages.



Thanks Vaclav. Modified the script to add corresponding table packages. code() function is great.


You are welcome.


Hi Vaclav,

I am certainly abusing your generous help. Can you also provide me info on how to generate the foreign key statements for the table.



in TDM you can define settings how to generate ref.integrity. Try to generate SQL and see tab Referential Integrity.

I don’t know if you want to generate the code for child entities or parent entities in your script. Below you can see script that uses child entity.

See modified code SaveDLL (full example at

function SaveDDL(Entity)
var Log = System.CreateObject(“Log”);
System.RegisterInterface( Log, ‘Log’);
var OutputFile, Content, Relation, RelationCode, i;
var Dialog = System.CreateObject(“SaveDialog”);
Dialog.InitialDir = “C:\”;
Dialog.FileName = Entity.Name + “.sql”;
OutputFile = new ActiveXObject(“Scripting.FileSystemObject”);
Content = OutputFile.CreateTextFile(Dialog.FileName, true);
**// relation DDL (iterated entity is child entity)
for(i=0; i<Entity.Relations.Count; i++)
Relation = Entity.Relations.GetObject(i);
// child entity check
if(Relation.ChildEntity == Entity)
} ** Content.Close();
OutputFile = null;
Log.Information("Entity DDL saved to file: " + Dialog.FileName);

Tips: PEREntity class has property Relations. See class PERRelation and its properties ParentEntity and ChildEntity.