PowerDesigner導出SQL時自動生成註釋

在powerBuilder中新建一個Physical Data Model,在其中新建一個用戶表,信息以下圖所示:sql

此時的SQL語句可從其中的Preview視圖中獲得,以下圖所示:數據庫

這個時候生成的sql語句是沒有註釋的,並且sql語句可能也不是適合本身所對應的數據庫語言。此時能夠經過如下方法來生成註釋而且選擇所需的數據庫語言。sqlserver

一、爲sql生成註釋,操做以下,我用的是PowerDesigner12.5,在其中選擇Tools----》Excute commands-----》Edit/Run Script打開的窗口中添加如下信息ui

'****************************************************************************** 
'*   File:           name2comment.vbs 
'*   Purpose:     Database   generation   cannot   use   object   names   anymore   
'                         in   version   7   and   above. 
'                         It   always   uses   the   object   codes. 
'
'                         In   case   the   object   codes   are   not   aligned   with   your   
'                         object   names   in   your   model,   this   script   will   copy   
'                         the   object   Name   onto   the   object   Comment   for   
'                         the   Tables   and   Columns. 
'
'*   Title:         
'*   Version:     1.0 
'*   Company:     Sybase   Inc.   
'******************************************************************************


Option Explicit
ValidationMode   = True
InteractiveMode   =   im_Batch

Dim   mdl   '   the   current   model

'   get   the   current   active   model 
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 If

'   This   routine   copy   name   into   comment   for   each   table,   each   column   and   each   view 
'   of   the   current   folder 
Private sub   ProcessFolder(folder) 
Dim   Tab   'running     table 
for each   Tab   in   folder.tables 
if not   tab.isShortcut   then
                  '把代表做爲表註釋,其實不用這麼作
                  tab.comment   =   tab.name 
Dim   col   '   running   column 
for each   col   in   tab.columns 
                        '把列name和comment合併爲comment
                        col.comment=   col.name 
next
end if
next

Dim   view   'running   view 
for each   view   in   folder.Views 
if not   view.isShortcut   then
                  view.comment   =   view.name 
end if
next

'   go   into   the   sub-packages 
Dim   f   '   running   folder 
For Each   f   In   folder.Packages 
if not   f.IsShortcut   then
                  ProcessFolder   f 
end if
Next
end sub

點擊run後,能夠看到剛剛的preview視圖窗口中已經以下圖所示this

二、更換數據庫sql語句。code

選擇Database---》change current DBMS,在DBMS中選擇對應的數據庫,如Microsoft SQL Server 2005,點擊肯定後,而後選擇Database---》Generate Database選項,在彈出的窗口中選擇生成sql文件的保存路徑,點擊肯定,則可看到生成的sql語言徹底是按照sqlserver2005的標準。server

相關文章
相關標籤/搜索