如何将列从公共表添加到企业架构中的新表

How to add columns from a Common Table to New Table in Enterprise Architect

本文关键字:企业 新表 添加      更新时间:2023-09-26

我正在使用Enterprise Architect 10工具为SQL数据库设计模式。

每当一个新表被添加到EA Schema(比如列'Name'和'Description')时,公共列(UserId, Status, Role, 15个这样的列)必须被添加到新表中。

目的表列=源表列+公共表列。

Destination表应该包含Name、Description、UserId、Status和Role列。

我有超过100个表,不能手动添加所有的公共列到每个表。

当我添加新表并执行脚本时,是否有任何规定或脚本(javascript或vbscript)可以执行此操作?

—在尝试后添加了此代码…

!INC Local Scripts.EAConstants-JScript

/**脚本名称:*作者:*的目的:*日期:*/

函数main (){//在这里输入脚本代码!//显示脚本输出窗口存储库。EnsureOutputVisible("Script");

// Get the currently selected element in the tree to work on
var theElement as EA.Element;
var theDestElement as EA.Element;
theElement = Repository.GetTreeSelectedObject();
//theDestElement = Repository.GetTreeSelectedObject();
//theDestElement.Name='Newtable1';
if( theElement != null && theElement.ObjectType == otElement)
{
    Session.Output( "Working on element '" + theElement.Name + "' (Type=" + theElement.Type +
        ", ID=" + theElement.ElementID + ")" );

    var srcAttributes as EA.Collection;
    srcAttributes = theElement.Attributes;
    theDestElement = Repository.
    Session.Output(theDestElement);
    theDestElement.Name='NewTable1';
    var dstAttributes as EA.Collection;
    dstAttributes = theDestElement.Attributes;
    newAttribute = null;
    // List attributes
    for ( var i = 0 ; i < srcAttributes.Count ; i++ )
    {
        var currentAttribute as EA.Attribute;
        currentAttribute = srcAttributes.GetAt( i );
        dstAttributes.AddNew(currentAttribute.,currentAttribute);
        //theDestElement

        Session.Output( "Attribute: " + currentAttribute.Name  );
    }
    Session.Output( "Done!" );
}
else
{
    // No item selected in the tree, or the item selected was not an element
    Session.Prompt( "This script requires an element be selected in the Project Browser.'n" +
        "Please select an element in the Project Browser and try again.", promptOK );
}

}

main ()

,

我可以使用

选择一个表的所有属性
theElement = Repository.GetTreeSelectedObject();

但是我不清楚要复制所有属性的目标表。

请帮助。

谢谢你,兰姆

首先,您可以使用模板包,其中放置了带有列的公共表。

要回顾性地完成它,您可以使用内部脚本支持来实现它。在EA中转到工具->脚本,寻找"VBScript -属性生命周期示例"或"JScript -属性生命周期示例",查看如何从元素中添加/删除属性。