Enterprise Architect 12版本使用教程
- 1.下载安装Enterprise Architect 12
- 2.Enterprise Architect原始DDL模板配置及存在的问题
- 1.DDL Column Definition原始模板(没有default值:可忽略)
- 2.DDL Data Type原始模板(timestamp等时间字段的长度默认为0:会报错)
- 3.DDL Name原始模板(对于数据库名的强引用不方便加表:可忽略)
- 4.DDl Script File原始模板(SET FOREIGN_KEY_CHECKS=0后面没有分号:会报错)
- 3.优化Enterprise Architect模板,适应mysql生成ddl
- 1.DDL Column Definition优化模板
- 2.DDL Data Type优化模板
- 3.DDL Name优化模板
- 4.DDl Script File优化模板
- 4.生成带注释的DDL语句
- 1.新建项目
- 2.新建数据库模型
- 3.添加元素(添加数据表)
- 4.设计字段
- 5.导出DDL
- 6.导入数据库
1.下载安装Enterprise Architect 12
下载地址
2.Enterprise Architect原始DDL模板配置及存在的问题
查看原始DDL模板
1.DDL Column Definition原始模板(没有default值:可忽略)
%PI=" "%
%DDLName("EA", "COLUMN", "", "INCLUDE_SURROUND")%
%DDLDataType%
$Type = %columnProperty:"TYPE"%
$Default = %columnProperty:"DEFAULT"%
$Find = ""
%if $Type != "ENUM" and $Type != "SET"%
%if $Default != ""%
$Find = %FIND($Default, "DEFAULT")%
%if $Find == "0"%
$Default = "DEFAULT " + $Default
%endIf%
%endIf%
%endIf%
%if columnBoolProperty:"ZEROFILL" == "T"%
ZEROFILL
%endIf%
%if columnBoolProperty:"UNSIGNED" == "T"%
UNSIGNED
%endIf%
%if columnBoolProperty:"NULLABLE" == "T"%
%if ddlOptionGenerateNullable == "T"%
NULL
%endIf%
%else%
NOT NULL
%endIf%
%if columnBoolProperty:"AutoNum" == "T"%
AUTO_INCREMENT
%else%
%if $Default != ""%
$Default
%endIf%
%endIf%
%DDLColumnComment%
%PI("I", "")%
,
2.DDL Data Type原始模板(timestamp等时间字段的长度默认为0:会报错)
%PI=""%
$Type = %columnProperty:"TYPE"%
$DBMS = %ddlTableDBMS%
$Size = %DDL_DATATYPE_SIZE($DBMS, $Type)%
$LENGTH = %columnProperty:"LENGTH"%
$Type
%if $Size=="1" and $LENGTH != "0" and $LENGTH != ""%
(
$LENGTH
)
%elseIf $Size=="2"%
(
%if columnProperty:"PRECISION"==""%
0
%else%
%columnProperty:"PRECISION"%
%endIf%
%if columnProperty:"SCALE" != ""%
,%columnProperty:"SCALE"%
%endIf%
)
%endIf%
3.DDL Name原始模板(对于数据库名的强引用不方便加表:可忽略)
%PI=""%
%if $parameter1 == "EA"%
%if $parameter3 == "INCLUDE_OWNER"%
$owner=%ddlOwner%
%if $parameter2 == "REFERENCE_TABLE"%
$owner=%ddlReferenceTableOwner%
%endIf%
%endIf%
%if $parameter2 == "OWNER"%
$name=%ddlOwner%
%elseIf $parameter2 == "TABLE"%
$name=%ddlTableName%
%if ddlUseAlias == "T"%
$alias=%ddlTableAlias%
%endIf%
%elseIf $parameter2 == "PROCEDURE"%
$name=%ddlProcedureName%
%if ddlUseAlias == "T"%
$alias=%ddlProcedureAlias%
%endIf%
%elseIf $parameter2 == "FUNCTION"%
$name=%ddlFunctionName%
%if ddlUseAlias == "T"%
$alias=%ddlFunctionAlias%
%endIf%
%elseIf $parameter2 == "VIEW"%
$name=%ddlViewName%
%if ddlUseAlias == "T"%
$alias=%ddlViewAlias%
%endIf%
%elseIf $parameter2 == "SEQUENCE"%
$name=%ddlSequenceName%
%if ddlUseAlias == "T"%
$alias=%ddlSequenceAlias%
%endIf%
%elseIf $parameter2 == "PACKAGE"%
$name=%ddlPackageName%
%if ddlUseAlias == "T"%
$alias=%ddlPackageAlias%
%endIf%
%elseIf $parameter2 == "COLUMN"%
$name=%ddlColumnName%
%if ddlUseAlias == "T"%
$alias=%ddlColumnAlias%
%endIf%
%elseIf $parameter2 == "CONSTRAINT"%
$name=%ddlConstraintName%
%if ddlUseAlias == "T"%
$alias=%ddlConstraintAlias%
%endIf%
%elseIf $parameter2 == "CONSTRAINT_COLUMN"%
$name=%ddlConstraintColumnName%
%if ddlUseAlias == "T"%
$alias=%ddlConstraintColumnAlias%
%endIf%
%elseIf $parameter2 == "REFERENCE_TABLE"%
$name=%ddlReferenceTableName%
%if ddlUseAlias == "T"%
$alias=%ddlReferenceTableAlias%
%endIf%
%elseIf $parameter2 == "REFERENCE_COLUMN"%
$name=%ddlReferenceColumnName%
%if ddlUseAlias == "T"%
$alias=%ddlReferenceColumnAlias%
%endIf%
%endIf%
%elseIf $parameter1 == "ODBC"%
%if $parameter3 == "INCLUDE_OWNER"%
$owner=%ddlSchemaOwner%
%endIf%
%if $parameter2 == "OWNER"%
$name=%ddlSchemaOwner%
%elseIf $parameter2 == "TABLE"%
$name=%ddlSchemaTableName%
%elseIf $parameter2 == "COLUMN"%
$name=%ddlSchemaColumnName%
%elseIf $parameter2 == "CONSTRAINT"%
$name=%ddlSchemaConstraintName%
%endIf%
%endIf%
%if $parameter4 == "INCLUDE_SURROUND"%
$left=%DDLLeftSurround%
$right=%DDLRightSurround%
%if $name != ""%
$name = $left + $name + $right
%endIf%
%if $alias != ""%
$alias = $left + $alias + $right
%endIf%
%if $owner != ""%
$owner = $left + $owner + $right
%endIf%
%endIf%
%if ddlOptionUseAlias == "T" and $alias != ""%
$fullName = $alias
%else%
$fullName = $name
%endIf%
%if $owner != ""%
$fullName = $owner + "." + $fullName
%endIf%
$fullName
4.DDl Script File原始模板(SET FOREIGN_KEY_CHECKS=0后面没有分号:会报错)
%PI="\n\n"%
%DDLScriptHeader%
%DDLUseDatabase%
$comment = ""
$start = ""
$end = ""
%if ddlOptionCommentLevel=="All"%
$comment = "T"
$start = "/*"
$end = "*/"
%endIf%
$fkCheckOff = "SET FOREIGN_KEY_CHECKS=0"
$fkCheckOff
%EXECUTE_STRING("Foreign Key Checks", "Set FK Check off", "820", $fkCheckOff)%
$script = %list="DDLDropView" @separator="\n\n"%
%if $script != ""%
%if $comment == "T"%
$start Drop Views $end
%endIf%
$script
%endIf%
$script = %list="DDLDropTable" @separator="\n\n"%
%if $script != ""%
%if $comment == "T"%
$start Drop Tables $end
%endIf%
$script
%endIf%
$script = %list="DDLDropProcedure" @separator="\n\n"%
%if $script != ""%
%if $comment == "T"%
$start Drop Stored Procedures $end
%endIf%
$script
%endIf%
$script = %list="DDLDropFunction" @separator="\n\n"%
%if $script != ""%
%if $comment == "T"%
$start Drop Functions $end
%endIf%
$script
%endIf%
$script = %list="DDLDropSequence" @separator="\n\n"%
%if $script != ""%
%if $comment == "T"%
$start Drop Sequences $end
%endIf%
$script
%endIf%
$script = %list="DDLCreateSequence" @separator="\n\n"%
%if $script != ""%
%if $comment == "T"%
$start Create Sequences $end
%endIf%
$script
%endIf%
$script = %list="DDLCreateFunction" @separator="\n\n"%
%if $script != ""%
%if $comment == "T"%
$start Create Functions $end
%endIf%
$script
%endIf%
$script = %list="DDLCreateTable" @separator="\n\n"%
%if $script != ""%
%if $comment == "T"%
$start Create Tables $end
%endIf%
$script
%endIf%
$script = %list="DDLCreateTableConstraints" @separator="\n\n"%
%if $script != ""%
%if $comment == "T"%
$start Create Primary Keys, Indexes, Uniques, Checks $end
%endIf%
$script
%endIf%
$script = %list="DDLCreateForeignKeys" @separator="\n\n"%
%if $script != ""%
%if $comment == "T"%
$start Create Foreign Key Constraints $end
%endIf%
$script
%endIf%
$fkCheckOff = "SET FOREIGN_KEY_CHECKS=1"
$fkCheckOff
%EXECUTE_STRING("Foreign Key Checks", "Set FK Check on", "300", $fkCheckOff)%
$script = %list="DDLCreateView" @separator="\n\n"%
%if $script != ""%
%if $comment == "T"%
$start Create Views $end
%endIf%
$script
%endIf%
$script = %list="DDLCreateProcedure" @separator="\n\n"%
%if $script != ""%
%if $comment == "T"%
$start Create Stored Procedures $end
%endIf%
$script
%endIf%
3.优化Enterprise Architect模板,适应mysql生成ddl
1.DDL Column Definition优化模板
%PI=" "%
%DDLName("EA", "COLUMN", "", "INCLUDE_SURROUND")%
%DDLDataType%
$Type = %columnProperty:"TYPE"%
$Default = %columnProperty:"DEFAULT"%
$Find = ""
%if $Type != "ENUM" and $Type != "SET"%
%if $Default != ""%
$Default = "DEFAULT " + $Default
%endIf%
%endIf%
%if columnBoolProperty:"ZEROFILL" == "T"%
ZEROFILL
%endIf%
%if columnBoolProperty:"UNSIGNED" == "T"%
UNSIGNED
%endIf%
%if columnBoolProperty:"NULLABLE" == "T"%
%if ddlOptionGenerateNullable == "T"%
NULL
%endIf%
%else%
NOT NULL
%endIf%
%if columnBoolProperty:"AutoNum" == "T"%
AUTO_INCREMENT
%else%
%if $Default != ""%
$Default
%endIf%
%endIf%
%DDLColumnComment%
%PI("I", "")%
,
2.DDL Data Type优化模板
%PI=""%
$Type = %columnProperty:"TYPE"%
$DBMS = %ddlTableDBMS%
$Size = %DDL_DATATYPE_SIZE($DBMS, $Type)%
$LENGTH = %columnProperty:"LENGTH"%
$Type
%if $Size=="1" and $LENGTH != "0" and $LENGTH != ""%
(
$LENGTH
)
%elseIf $Size=="2"%
(
%if columnProperty:"PRECISION"==""%
0
%else%
%columnProperty:"PRECISION"%
%endIf%
%if columnProperty:"SCALE" != ""%
,%columnProperty:"SCALE"%
%endIf%
)
%endIf%
3.DDL Name优化模板
%PI=""%
%if $parameter1 == "EA"%
%if $parameter3 == "INCLUDE_OWNER"%
$owner=%ddlOwner%
%if $parameter2 == "REFERENCE_TABLE"%
$owner=%ddlReferenceTableOwner%
%endIf%
%endIf%
%if $parameter2 == "OWNER"%
$name=%ddlOwner%
%elseIf $parameter2 == "TABLE"%
$name=%ddlTableName%
%if ddlUseAlias == "T"%
$alias=%ddlTableAlias%
%endIf%
%elseIf $parameter2 == "PROCEDURE"%
$name=%ddlProcedureName%
%if ddlUseAlias == "T"%
$alias=%ddlProcedureAlias%
%endIf%
%elseIf $parameter2 == "FUNCTION"%
$name=%ddlFunctionName%
%if ddlUseAlias == "T"%
$alias=%ddlFunctionAlias%
%endIf%
%elseIf $parameter2 == "VIEW"%
$name=%ddlViewName%
%if ddlUseAlias == "T"%
$alias=%ddlViewAlias%
%endIf%
%elseIf $parameter2 == "SEQUENCE"%
$name=%ddlSequenceName%
%if ddlUseAlias == "T"%
$alias=%ddlSequenceAlias%
%endIf%
%elseIf $parameter2 == "PACKAGE"%
$name=%ddlPackageName%
%if ddlUseAlias == "T"%
$alias=%ddlPackageAlias%
%endIf%
%elseIf $parameter2 == "COLUMN"%
$name=%ddlColumnName%
%if ddlUseAlias == "T"%
$alias=%ddlColumnAlias%
%endIf%
%elseIf $parameter2 == "CONSTRAINT"%
$name=%ddlConstraintName%
%if ddlUseAlias == "T"%
$alias=%ddlConstraintAlias%
%endIf%
%elseIf $parameter2 == "CONSTRAINT_COLUMN"%
$name=%ddlConstraintColumnName%
%if ddlUseAlias == "T"%
$alias=%ddlConstraintColumnAlias%
%endIf%
%elseIf $parameter2 == "REFERENCE_TABLE"%
$name=%ddlReferenceTableName%
%if ddlUseAlias == "T"%
$alias=%ddlReferenceTableAlias%
%endIf%
%elseIf $parameter2 == "REFERENCE_COLUMN"%
$name=%ddlReferenceColumnName%
%if ddlUseAlias == "T"%
$alias=%ddlReferenceColumnAlias%
%endIf%
%endIf%
%elseIf $parameter1 == "ODBC"%
%if $parameter3 == "INCLUDE_OWNER"%
$owner=%ddlSchemaOwner%
%endIf%
%if $parameter2 == "OWNER"%
$name=%ddlSchemaOwner%
%elseIf $parameter2 == "TABLE"%
$name=%ddlSchemaTableName%
%elseIf $parameter2 == "COLUMN"%
$name=%ddlSchemaColumnName%
%elseIf $parameter2 == "CONSTRAINT"%
$name=%ddlSchemaConstraintName%
%endIf%
%endIf%
%if $parameter4 == "INCLUDE_SURROUND"%
$left=%DDLLeftSurround%
$right=%DDLRightSurround%
%if $name != ""%
$name = $left + $name + $right
%endIf%
%if $alias != ""%
$alias = $left + $alias + $right
%endIf%
%if $owner != ""%
$owner = $left + $owner + $right
%endIf%
%endIf%
%if ddlOptionUseAlias == "T" and $alias != ""%
$fullName = $alias
%else%
$fullName = $name
%endIf%
$fullName
4.DDl Script File优化模板
%PI="\n\n"%
%DDLScriptHeader%
%DDLUseDatabase%
$comment = ""
$start = ""
$end = ""
%if ddlOptionCommentLevel=="All"%
$comment = "T"
$start = "/*"
$end = "*/"
%endIf%
$fkCheckOff = "SET FOREIGN_KEY_CHECKS=0;"
$fkCheckOff
%EXECUTE_STRING("Foreign Key Checks", "Set FK Check off", "820", $fkCheckOff)%
$script = %list="DDLDropView" @separator="\n\n"%
%if $script != ""%
%if $comment == "T"%
$start Drop Views $end
%endIf%
$script
%endIf%
$script = %list="DDLDropTable" @separator="\n\n"%
%if $script != ""%
%if $comment == "T"%
$start Drop Tables $end
%endIf%
$script
%endIf%
$script = %list="DDLDropProcedure" @separator="\n\n"%
%if $script != ""%
%if $comment == "T"%
$start Drop Stored Procedures $end
%endIf%
$script
%endIf%
$script = %list="DDLDropFunction" @separator="\n\n"%
%if $script != ""%
%if $comment == "T"%
$start Drop Functions $end
%endIf%
$script
%endIf%
$script = %list="DDLDropSequence" @separator="\n\n"%
%if $script != ""%
%if $comment == "T"%
$start Drop Sequences $end
%endIf%
$script
%endIf%
$script = %list="DDLCreateSequence" @separator="\n\n"%
%if $script != ""%
%if $comment == "T"%
$start Create Sequences $end
%endIf%
$script
%endIf%
$script = %list="DDLCreateFunction" @separator="\n\n"%
%if $script != ""%
%if $comment == "T"%
$start Create Functions $end
%endIf%
$script
%endIf%
$script = %list="DDLCreateTable" @separator="\n\n"%
%if $script != ""%
%if $comment == "T"%
$start Create Tables $end
%endIf%
$script
%endIf%
$script = %list="DDLCreateTableConstraints" @separator="\n\n"%
%if $script != ""%
%if $comment == "T"%
$start Create Primary Keys, Indexes, Uniques, Checks $end
%endIf%
$script
%endIf%
$script = %list="DDLCreateForeignKeys" @separator="\n\n"%
%if $script != ""%
%if $comment == "T"%
$start Create Foreign Key Constraints $end
%endIf%
$script
%endIf%
$fkCheckOff = "SET FOREIGN_KEY_CHECKS=1;"
$fkCheckOff
%EXECUTE_STRING("Foreign Key Checks", "Set FK Check on", "300", $fkCheckOff)%
$script = %list="DDLCreateView" @separator="\n\n"%
%if $script != ""%
%if $comment == "T"%
$start Create Views $end
%endIf%
$script
%endIf%
$script = %list="DDLCreateProcedure" @separator="\n\n"%
%if $script != ""%
%if $comment == "T"%
$start Create Stored Procedures $end
%endIf%
$script
%endIf%
4.生成带注释的DDL语句
1.新建项目
2.新建数据库模型
3.添加元素(添加数据表)
4.设计字段
注意:如果想让主键自增,实现以下效果,记得修改主键字段配置
5.导出DDL