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.EA生成带注释的DDL语句,导入MySQL数据库
1.新建项目
2.新建数据库模型
3.添加元素(添加数据表)
4.设计字段
4.1注意:如果想让主键自增,实现在代码中id自增的效果,记得修改主键字段配置
5.导出DDL
6.导入数据库
6.1关于创建时间和修改时间自动填充更新的问题
要实现Java程序在插入数据时自动填充创建时间,在修改数据时自动填充修改时间,需要改一下相关字段的默认值
6.1.1 在新建表时配置
自动获取创建时间:timestamp not null default CURRENT_TIMESTAMP
自动获取更新时间:timestamp not null default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP
create table test(
id integer not null auto_increment primary key,
name varchar(20) not null ,
create_time timestamp not null default CURRENT_TIMESTAMP COMMENT '创建时间',
update_time timestamp not null default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP COMMENT '更新时间');
6.1.2 在修改现有表时配置
1用sql语句改
ALTER TABLE test MODIFY create_time timestamp not null default CURRENT_TIMESTAMP COMMENT '创建时间';
ALTER TABLE test MODIFY update_time timestamp not null default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP COMMENT '更新时间';
2用客户端改
创建时间默认值设为CURRENT_TIMESTAMP
修改时间默认值设为CURRENT_TIMESTAMP,同时勾选“根据当前时间戳更新”
5.将MySQL数据库导入到EA
1.下载安装mysql-connector-odbc
下载地址:https://download.csdn.net/download/weixin_44330367/89154248
根据使用的mysql版本选择对应的驱动进行安装(尽量选择32位的),傻瓜式安装过程省略
2.在管理工具中新增ODBC数据源
3.在EA中新建项目
4.链接MYSQL数据源
4.1 安装64位的ODBC驱动可能出现”在连接ODBC 时发生错误,请相关检查设置“的提示,卸载后重新安装32位ODBC驱动后可以正常执行
文章来源:https://www.toymoban.com/news/detail-858494.html
6.导入MYSQL的数据库
文章来源地址https://www.toymoban.com/news/detail-858494.html
到了这里,关于Enterprise Architect 12版本使用教程的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!