微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

sql – 从Microsoft Access创建表的DDL

有没有任何简单的方法从Microsoft Access(2007)检索表创建DDL,或者我必须使用VBA自己编写它来读取表结构?

我有大约30个表,我们正在移植到Oracle,如果我们可以从Access定义创建表,这将使生活更轻松.

解决方法

感谢其他建议.当我在等待时,我写了一些VBA代码来做到这一点.这不是完美的,但为我做了工作.
Option Compare Database
Public Function TableCreateDDL(TableDef As TableDef) As String

         Dim fldDef As Field
         Dim Fieldindex As Integer
         Dim fldName As String,fldDataInfo As String
         Dim DDL As String
         Dim TableName As String

         TableName = TableDef.Name
         TableName = Replace(TableName," ","_")
         DDL = "create table " & TableName & "(" & vbCrLf
         With TableDef
            For Fieldindex = 0 To .Fields.Count - 1
               Set fldDef = .Fields(Fieldindex)
               With fldDef
                  fldName = .Name
                  fldName = Replace(fldName,"_")
                  Select Case .Type
                     Case dbBoolean
                        fldDataInfo = "nvarchar2"
                     Case dbByte
                        fldDataInfo = "number"
                     Case dbInteger
                        fldDataInfo = "number"
                     Case dbLong
                        fldDataInfo = "number"
                     Case dbCurrency
                        fldDataInfo = "number"
                     Case dbSingle
                        fldDataInfo = "number"
                     Case dbDouble
                        fldDataInfo = "number"
                     Case dbDate
                        fldDataInfo = "date"
                     Case dbText
                        fldDataInfo = "nvarchar2(" & Format$(.Size) & ")"
                     Case dbLongBinary
                        fldDataInfo = "****"
                     Case dbMemo
                        fldDataInfo = "****"
                     Case dbGUID
                        fldDataInfo = "nvarchar2(16)"
                  End Select
               End With
               If Fieldindex > 0 Then
               DDL = DDL & "," & vbCrLf
               End If
               DDL = DDL & "  " & fldName & " " & fldDataInfo
               Next Fieldindex
         End With
         DDL = DDL & ");"
         TableCreateDDL = DDL
End Function


Sub ExportAllTableCreateDDL()

    Dim lTbl As Long
    Dim dBase As Database
    Dim Handle As Integer

    Set dBase = CurrentDb

    Handle = FreeFile

    Open "c:\export\TableCreateDDL.txt" For Output Access Write As #Handle

    For lTbl = 0 To dBase.TableDefs.Count - 1
         'If the table name is a temporary or system table then ignore it
        If Left(dBase.TableDefs(lTbl).Name,1) = "~" Or _
        Left(dBase.TableDefs(lTbl).Name,4) = "MSYS" Then
             '~ indicates a temporary table
             'MSYS indicates a system level table
        Else
          Print #Handle,TableCreateDDL(dBase.TableDefs(lTbl))
        End If
    Next lTbl
    Close Handle
    Set dBase = nothing
End Sub

我从来没有声称是VB程序员.

原文地址:https://www.jb51.cc/mssql/81452.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐