日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

powerdesigner-建立数据库模型及全局脚本

發布時間:2024/9/27 数据库 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 powerdesigner-建立数据库模型及全局脚本 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

powerdesigner 使用

文章目錄

    • powerdesigner 使用
      • 1. 建立數據庫表模型
      • 2. 腳本統一修改表結構(賦值默認字段、統一刪除、統一修改)
        • 2.1.統一添加默認字段:
        • 2.2.統一刪除字段:
        • 2.3.統一修改表名稱:
        • 2.4. 統一修改字段屬性:
        • 2.5.其他函數

1. 建立數據庫表模型

1.1.創建模型,并選擇數據庫類型

1.2 建立表

1.3.修改表名稱

1.4.編輯表結構
1.5.編輯索引

1.6.查看sql語句

2. 腳本統一修改表結構(賦值默認字段、統一刪除、統一修改)


tools - execute commands - edit/ run Scripe 打開窗口輸入vb腳本命令

2.1.統一添加默認字段:

對于需要排除在外的表,可添加在下面代碼中:
if instr(",Ex1,Ex2,",","+CurrentObject.Code+",")>0 then exit sub

Option Explicit ValidationMode = True InteractiveMode = im_BatchDim mdl Set mdl = ActiveModel If (mdl Is Nothing) ThenMsgBox "There is no Active Model" ElseListObjects(mdl) End IfPrivate Sub ListObjects(fldr) output "Scanning " & fldr.codeDim obj For Each obj In fldr.childrenTableSetComment objNextDim f For Each f In fldr.Packages ListObjects fNext End SubPrivate Sub TableSetComment(CurrentObject)if not CurrentObject.Iskindof(cls_Table) then exit subif instr(",Ex1,Ex2,",","+CurrentObject.Code+",")>0 then exit subif not CurrentObject.isShortcut thenDim col Dim numdim create_user_iddim create_timedim update_user_iddim update_timedim is_deletecreate_user_id=1update_user_id=1create_time=1update_time=1is_delete=1for each col in CurrentObject.columnsnum= num + 1if col.Code="create_user_id" thencreate_user_id=100end ifif col.Code="create_time" thencreate_time=100end ifif col.Code="update_user_id" thenupdate_user_id=100end ifif col.Code="update_time" thenupdate_time=100end ifif col.Code="is_delete" thenis_delete=100end ifnextif create_user_id=1 then CurrentObject.columns.CreateNewAt(num)for each col in CurrentObject.columns if col.DataType="" then col.Name="創建人"col.Code="create_user_id"col.Comment="創建人"col.DataType="varchar(64)"col.Mandatory=1end if nextnum=num+1end ifif create_time=1 then CurrentObject.columns.CreateNewAt(num)for each col in CurrentObject.columns if col.DataType="" then col.Name="創建時間"col.Code="create_time"col.Comment="創建時間"col.DataType="datetime"col.DefaultValue="CURRENT_TIMESTAMP"end if nextnum=num+1end ifif update_user_id=1 then CurrentObject.columns.CreateNewAt(num)for each col in CurrentObject.columns if col.DataType="" then col.Name="修改人"col.Code="update_user_id"col.Comment="修改人"col.DataType="varchar(64)" end if nextnum=num+1end ifif update_time=1 then CurrentObject.columns.CreateNewAt(num)for each col in CurrentObject.columns if col.DataType="" then col.Name="修改時間"col.Code="update_time"col.Comment="修改時間"col.DataType="datetime"col.DefaultValue="CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"end if nextnum=num+1end ifif is_delete=1 then CurrentObject.columns.CreateNewAt(num)for each col in CurrentObject.columns if col.DataType="" then col.Name="刪除標志"col.Code="is_delete"col.Comment="刪除標志"col.DataType="tinyint"col.DefaultValue="0"end if nextnum=num+1end ifend if End Sub

2.2.統一刪除字段:

對于需要排除在外的表,可添加在下面代碼中:
if instr(",Ex1,Ex2,",","+tab.Code+",")=0 then

Option Explicit ValidationMode = True InteractiveMode = im_BatchDim mdl Set mdl = ActiveModel If (mdl Is Nothing) Then MsgBox "There is no current Model" ElseIf Not mdl.IsKindOf(PdPDM.cls_Model) Then MsgBox "The current model is not an Physical Data model." Else ProcessFolder mdl End IfPrivate sub ProcessFolder(CurrentObject)Dim Tab for each Tab in CurrentObject.tablesif instr(",Ex1,Ex2,",","+tab.Code+",")=0 then if not tab.isShortcut thenDim col for each col in tab.columnsif instr(col.code,"update_user_id")<>0 thencol.Deleteend ifif instr(col.code,"update_time")<>0 thencol.Deleteend ifif instr(col.code,"create_user_id")<>0 thencol.Deleteend ifif instr(col.code,"create_time")<>0 thencol.Deleteend ifnextend ifend ifnext MsgBox "success"end sub

2.3.統一修改表名稱:

Option Explicit ValidationMode = True InteractiveMode = im_BatchDim mdl Set mdl = ActiveModel If (mdl Is Nothing) Then MsgBox "There is no current Model" ElseIf Not mdl.IsKindOf(PdPDM.cls_Model) Then MsgBox "The current model is not an Physical Data model." ElseProcessFolder mdl End IfPrivate sub ProcessFolder(CurrentObject)Dim Tab Dim NameStr , CodeStrfor each Tab in CurrentObject.tables Tab.name = Replace( Tab.name , "ori_name" , "new_name")Tab.code = Replace( Tab.code , "s_" , "student_")nextMsgBox "success" end sub

2.4. 統一修改字段屬性:

對于需要排除在外的表,可添加在下面代碼中:
if instr(",Ex1,Ex2,",","+tab.Code+",")=0 then

dim model set model = ActiveModel If (model Is Nothing) ThenMsgBox "There is no current Model"ElseIf Not model.IsKindOf(PdPDM.cls_Model) ThenMsgBox "The current model is not an Physical Data model."ElseProcessTables modelProcessSequences modelMsgBox "success" End Ifsub ProcessSequences(folder)dim sequencefor each sequence in folder.sequencessequence.name = LCase(sequence.name)sequence.code = LCase(sequence.code)nextend subsub ProcessTables(folder)dim tablefor each table in folder.tablesif instr(",Ex1,Ex2,",","+table.Code+",")=0 then if not table.IsShortCut then ProcessTable tableend ifend ifnextdim subFolderfor each subFolder in folder.PackagesProcessTables subFoldernext end subsub ProcessTable(table)dim colfor each col in table.Columnsif col.code = "s_name" then col.code = "student_name" col.DataType = "vachar(64)"col.DefaultValue="1"col.Mandatory=0end ifcol.code = LCase(col.code)col.name = LCase(col.name)next table.name = UCase(table.name)table.code = UCase(table.code)end sub

對于其他需要修改的屬性,可在ProcessTable方法中自定義編輯代碼

2.5.其他函數

在2.4.中將ProcessTables subFolder調用的方法替換為下述方法即可

表字段的部分替換:

sub ReplaceCol(table)dim colfor each col in table.Columnsif instr(col.code,qty)>0 then col.code = Replace(col.code,"qty","quantity")end ifif instr(col.code,amt)>0 then col.code = Replace(col.code,"amt","amount")end ifnext end sub

總結

以上是生活随笔為你收集整理的powerdesigner-建立数据库模型及全局脚本的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。