一、生成脚本的时候,去掉外键关联

PowerDesigner 自定义脚本_自定义


二、生成自定义的表注释

code:

/*
表名:%TNAME%
*/
create table [%QUALIFIER%]%TABLE%
(
%TABLDEFN%
)
[%OPTIONS%]


PowerDesigner 自定义脚本_自定义_02

PowerDesigner 自定义脚本_数据_03

生成后的效果预览:

PowerDesigner 自定义脚本_表名_04


三、让建表语句可以重复执行,并且为每个表都增加上通用字段

/*
表名:%TNAME%
*/
if not exists (select 1
from sysobjects
where id = object_id('[%QUALIFIER%]%TABLE%')
and type = 'U'
begin
create table [%QUALIFIER%]%TABLE%
(
create_user bigint comment '创建人',
create_time datetime comment '创建时间',
update_user bigint comment '上次修改人',
update_time datetime comment '上次修改时间',
is_deleted int comment '是否已删除',
sort int comment '排序',
tenant_id varchar(12) comment '租户id',
create_dept bigint comment '创建部门',

%TABLDEFN%
)
[%OPTIONS%]
end


四、MySQL脚本自定义

/*
表名:%TNAME%
*/
DROP TABLE IF EXISTS `[%QUALIFIER%]%TABLE%`;
CREATE TABLE [%QUALIFIER%]%TABLE%
(
create_user bigint comment '创建人',
create_time datetime comment '创建时间',
update_user bigint comment '更新人',
update_time datetime comment '更新时间',
status int comment '业务状态[1:正常]',
is_deleted int comment '是否已删除[0:未删除,1:删除]',
tenant_id varchar(12) comment '租户id',

%TABLDEFN%
)
[%OPTIONS%]


五、去掉SQL语句里面的'on "PRIMARY";'

PowerDesigner 自定义脚本_自定义_05


六、批量生成SQL语句

PowerDesigner 自定义脚本_自定义_06


七、在批量生成语句里面,去掉'create user dbo;'

PowerDesigner 自定义脚本_字段_07

删除这个user更好

PowerDesigner 自定义脚本_表名_08


八、特别注意

MySQL数据库设计的时候,ower不能选择dbo,这点特别注意

PowerDesigner 自定义脚本_自定义_09


九、设置导出的SQL文件的编码格式,指定为utf-8格式即可

PowerDesigner 自定义脚本_sql语句_10


十、对第九条的补充。用 Navicat Premium 批量导入数据前,需要把生成的SQL语句的编码转换为utf-8,不然字段备注那些会乱码

PowerDesigner 自定义脚本_自定义_11

PowerDesigner 自定义脚本_字段_12

.