当前位置:   article > 正文

Enterprise Architect 12版本使用教程

enterprise architect

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", "")%
,
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48

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%
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27

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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118

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%
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121

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", "")%
,
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45

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%
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29

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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114

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%
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121

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 '更新时间');
  • 1
  • 2
  • 3
  • 4
  • 5
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 '更新时间';
  • 1
  • 2

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驱动后可以正常执行

在这里插入图片描述
在这里插入图片描述

6.导入MYSQL的数据库

在这里插入图片描述
在这里插入图片描述

本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号