网上有很多利用mssql中备注的方法,其实那些都不实用,一般在一个企业数据库中,经常会有数据字典,从数据字典中,导入备注说明之类的才是比较实用的。下面代码就是为这点而做的。
'******************************************************************************
'* File: ODBCConnect.vbs
'* Purpose: Show how to use an ODBC connection
' list the non-empty tables
'* Title:
'* Category:
'* Version: 1.0
'* Company: Sybase Inc.
'******************************************************************************
Option Explicit
Dim model
Set model = ActiveModel
If (model Is Nothing) Or (Not model.IsKindOf(PdPDM.cls_Model)) Then
MsgBox "The current model is not a PDM model."
Else
ChangeName model
End If
sub ChangeName(package)
Const CONNECTION = "Data Source=his;User Id=sa;Password=sa;"
Dim cnx ' connection object
set cnx = CreateObject("ADODB.Connection")
cnx.Open CONNECTION
Dim rs ' recordset
set rs = cnx.Execute("select table_name,table_chinese from wh_table_struc where table_chinese is not null and table_name in (select distinct table_name from wh_field_struc where field_chinese is not null) order by table_name")
Output "List of non-empty tables:"
Dim n ' row count
Dim return
Dim tablename
dim tabledesc
Do Until rs.EOF
tablename =rs("table_name")
tabledesc =rs("table_chinese")
if SetNameDesc(package, tablename, tabledesc,cnx) then
end if
rs.MoveNext
Loop
rs.Close
set rs = Nothing
cnx.Close
set cnx = Nothing
end sub
'-----------------------------------------------------------------------------
' Display tables properties defined in a folder
'-----------------------------------------------------------------------------
function SetNameDesc(package, Name, Desc,cnx)
' Get the Tables collection
Dim ModelTables
Set ModelTables = package.Tables
' For each table
Dim noTable
Dim tbl
Dim bShortcutClosed
noTable = 1
For Each tbl In ModelTables
If IsObject(tbl) Then
If Not tbl.IsShortcut Then
IF trim(tbl.name) = trim(Name) Then
'Output "Tables are Same" + CStr(Name) + ":"
if trim(tbl.name) = trim(tbl.code) then
tbl.comment = Desc
end if
'更改字段内容。
Dim field
Dim rs
For each field in tbl.Columns
if IsObject(field) then
set rs = cnx.Execute("select field_chinese from wh_field_struc where field_name ='"& trim(field.name)&"' and table_name ='"&trim(tbl.name)&"' and field_chinese is not null")
If Not rs.EOF Then
field.comment = rs("field_chinese")
End If
set rs = nothing
end if
Next
noTable = 0
SetNameDesc = true
Exit For
end if
End If
End If
noTable = noTable + 1
Next
' Display tables defined in subpackages
'Output Name
' Output noTable
if noTable <> 0 then
' Output "In Package"
Dim subpackage
For Each subpackage in package.Packages
If Not subpackage.IsShortcut Then
if SetNameDesc(subpackage, Name, Desc,cnx) = true then
Output "In Package"
Exit for
end if
End If
Next
end if
End function