I’m currently modeling a new database in TDM (MSSQL) and need to add audit tables for a handful of entities.
Whilst I could sit here and manually add them, as the number of tables requiring auditing is going to grow over the next year as the database is extended I was wondering whether it’s possible to create a macro that would allow me to select an existing table and for it to automatically copy all of the attributes and descriptions to a new table, to add a further 4 auditing columns including a PK along with a couple of check constraints.
Has anyone attempted this or is there any examples lying around that might help?
it is possible to write or modify a macro that will do majority of tasks you require. I’d like to note that some of the functionality might already be available, see the following page: http://www.casestudio.com/help/ProductivityPack.aspx
And if you wish to define new table with predefined columns, you can use gallery.
Click Help | Help Topics and navigate to page Help | Features | Gallery.
I thought I’d get on and have a go at creating a script from scratch yesterday and so far I’ve managed to get it to create the entity, add the additional attributes along with descriptions and schema information and to also copy all of the existing attributes from a table.
I’m currently trying to create a new PK, but having a couple of difficulties. Do you have a code snippet lying around that shows how to add a PK?
More info: there always is one empty primary key in each new table. Therefore you don’t create new primary key, but set the InVisible param to false.
Unfortunately, it is not possible to change primary key via scripting in the current version of TDM. I mean if you created another key and wanted to change the existing primary key to the second key, that would be possible to do manually only.
Hi Kevin,
if you right click on an entity in Model Explorer it will appear. If you want same behaviour on workspace you need select on the ‘Object Types’ tab ‘Entity Shortcut’ (under Workspace).
If you do it, you need check type of object in This.GetObject(i); in macro. It may be Entity, or Entity Shortcut. You can use something similar:
var Obj = This.GetObject(i);
if (Obj.ObjectType != 2002) //2002 is Object Type of PER Entity
Obj = Obj.ParentBase;