我怎样查看 Microsoft Access 2013表格 的元数据(数据字典)?
我怎样查看 Microsoft Access 2013表格 的元数据(数据字典)?
SELECT Name, DateCreate, DateUpdate,
iif(LEFT(Name, 4) = 'MSys','System Table',
iif(type = 2,'System Object',
iif(type = 3,'System Object',
iif(type = 8,'System Object',
iif(type = 4,'Linked Table (ODBC)',
iif(type = 1,'Table',
iif(type = 6, 'Linked Table (MsAccess/MsExcel)',
iif(type = 5,'Query',
iif(type = -32768,'Form',
iif(type = -32764,'Report',
iif(type=-32766,'Macro',
iif(type = -32761,'Module',
iif(type = -32756,'Page',
iif(type = -32758,'User','Unknown')))))))))))))) as ObjectType
FROM MSysObjects WHERE LEFT(Name, 1) <> '~'
如果您不想显示系统对象,可以将以下条件添加到where子句中:
AND LEFT(Name, 4) <> 'MSys' AND Type IN (1, 5, 4, 6, -32768, -32764, -32766, -32761,-32756,-32758)
我还创建了一个应用程序,从访问数据库中检索数据,我为此创建了一个新的Git存储库
DAO.TableDef
对象可以帮助您:dim db as DAO.Database, tbl as DAO.TableDef
dim f as DAO.Field
set db = currentdb() ' Connect to current database
' Loop through each table in the database
for each tbl in db.tableDefs
debug.print "Table name: ", tbl.Name
' Loop throuth each field in the table
for each f in tbl.Fields
debug.print "Field: ", f.Name
next f
next tbl
TableDef
对象 (DAO
)
- Field
对象 (DAO
)
Sub GenerateDataDictionary()
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field
Dim rs As DAO.Recordset
Dim DataDictionaryTableName As String
DataDictionaryTableName = "__DataDictionary"
Set db = CurrentDb
If Not TableExists(db, DataDictionaryTableName) Then
Set tdf = db.CreateTableDef(DataDictionaryTableName)
With tdf
.Fields.Append .CreateField("TableName", dbText, 255)
.Fields.Append .CreateField("Position", dbLong)
.Fields.Append .CreateField("ColumnName", dbText, 255)
.Fields.Append .CreateField("Type", dbText, 255)
.Fields.Append .CreateField("Size", dbLong)
.Fields.Append .CreateField("Description", dbMemo)
End With
db.TableDefs.Append tdf
Application.RefreshDatabaseWindow
Else
db.Execute "DELETE * FROM " & DataDictionaryTableName, dbFailOnError
End If
Set rs = db.OpenRecordset(DataDictionaryTableName)
For Each tdf In db.TableDefs
If tdf.Name = DataDictionaryTableName Then GoTo SkipTable
If Left(tdf.Name, 1) = "~" Then GoTo SkipTable
If Left(tdf.Name, 4) = "MSys" Then GoTo SkipTable
If Left(tdf.Name, 4) = "USys" Then GoTo SkipTable
If tdf.Connect <> "" Then GoTo SkipTable
Select Case tdf.Name
Case "Version", "VersionDetail"
GoTo SkipTable
Case Else
For Each fld In tdf.Fields
With rs
.AddNew
!TableName = tdf.Name
!Position = fld.OrdinalPosition
!ColumnName = fld.Name
Select Case fld.Type
Case dbDate: !Type = "Date/Time"
Case dbText
!Type = "Short Text"
!size = fld.size
Case dbBoolean: !Type = "Yes/No"
Case dbMemo: !Type = "Long Text"
Case dbByte: !Type = "Int8"
Case dbInteger: !Type = "Int16"
Case dbLong: !Type = "Int32"
Case dbSingle: !Type = "Single"
Case dbDouble: !Type = "Double"
Case dbDecimal: !Type = "Decimal"
Case dbCurrency: !Type = "Currency"
End Select
On Error Resume Next
!Description = fld.Properties("Description")
On Error GoTo 0
.Update
End With
Next fld
End Select
SkipTable:
Next tdf
MsgBox "Done"
End Sub
Function TableExists(db As DAO.Database, TableName As String) As Boolean
Dim tdf As DAO.TableDef
For Each tdf In db.TableDefs
If tdf.Name = TableName Then
TableExists = True
Exit Function
End If
Next tdf
TableExists = False
End Function