代码之家  ›  专栏  ›  技术社区  ›  user128300

如何确定哪个表在Access数据库中使用的空间最多

  •  10
  • user128300  · 技术社区  · 16 年前

    是否有任何简单的方法来确定Access2007数据库中每个表所使用的空间?

    我有一个异常大的Access数据库,需要找出哪个表使用的空间最大。行数不能提供有关已用空间的足够信息。

    当做

    弗兰克

    5 回复  |  直到 7 年前
        1
  •  4
  •   Tony Toews    16 年前

    对于运行的Access数据库,您可以使用简单的工具 Access Memory Reporter 1.0 它显示了表和索引所需的内存量。注意,我自己还没试过这个工具。

    一旦你发现最大的桌子,你的目标是什么?你的MDB有多大?你最近压缩了吗?

    当你压缩它时它会收缩多少?这就是您在创建和删除其中的许多表/记录吗?如果是这样的话 TempTables.MDB page 在我的网站上,它演示了如何在应用程序中使用临时MDB。

    你在桌子上用了很多图形吗?

        2
  •  5
  •   Luke Chung    16 年前

    这实际上是一个有趣的问题,因为Access使用可变长度的记录来存储数据。

    最好的方法是仔细检查表中的每个记录和字段,并将字段的长度相加。如果桌子很大,可能需要一段时间。由于索引和关系的原因,它不会占用大小。

    在我们的total access analyzer程序中,我们有一些报告使用简单的记录大小估计值乘以记录数来提供表大小的估计值。示例如下: http://fmsinc.com/MicrosoftAccess/Documentation/Reports/Table_SizeBySize.html

    这可能足以进行大致的估计或相对大小的比较。

    另一种可能非常准确的方法是创建一个新的数据库并将表导出到其中。压缩数据库并从中减去空白数据库大小以获得表的大小。

        3
  •  5
  •   Ben    8 年前

    我知道这是一篇老文章,但我有一个基于我自己对同一问题的经验的解决方案。我的解决方案是将所有表导出到文本文件。每个文本文件的大小大致与它在mdb/accdb文件中使用的空间大小成正比。

    下面的代码将创建一个子文件夹“ TavePiTable尺寸 “并将所有表导出到当前数据库文件夹下。您可以向它传递一个参数来只处理本地表。完成后,它会告诉您导出了多少表,并询问您是否要打开文件夹。按大小对文件夹进行排序,您将很快识别出罪犯。我使用这个例程来查找可能在部署前忘记清除的表,或者帮助我了解在继承别人的数据库时大表在哪里。

    为了使这个例程对我更方便,我将这个代码添加到一个Access外接程序中,这样我就可以针对任何数据库运行它。该外接程序还具有导出所有其他Access对象的功能,因此我可以查看哪些窗体/报表占用了数据库中的空间。如果有兴趣的话,我可以找个地方分享。

    Public Sub DocDatabase_Table(Optional bolLocalTablesOnly As Boolean = False)
     '====================================================================
     ' Name:    DocDatabase_Table
     ' Purpose: Exports the tables in this database to a series of
     '          text files.  The size of each text file will give you
     '          an idea of what tables use the most disk space.
     '
     ' Author:  Ben Sacherich
     ' Date:    5/2/2011
     '====================================================================
        On Error GoTo ErrorHandler
    
        Dim dbs As Database ' or Variant if this fails.
        Dim td As TableDef
        Dim strSaveDir As String
        Dim lngObjectCount As Long
        Dim lngCount As Long
        Dim strMsg As String
        Dim varReturn As Variant
    
        Set dbs = CurrentDb() ' use CurrentDb() to refresh Collections
    
        ' Export to a subfolder of the current database folder.
        strSaveDir = CurrentProject.path & "\temp_table_size\"
    
        If Len(strSaveDir) > 0 Then
    
            strMsg = "This feature exports all of the tables in this database to a series of " _
                & "comma delimited text files.  The size of each text file will give you " _
                & "an idea of what tables use the most disk space." & vbCrLf & vbCrLf
    
            ' Get a count of the tables, minus the system tables.
            If bolLocalTablesOnly = True Then
                lngObjectCount = DCount("Name", "MSysObjects", "Type=1 AND Name not like 'MSys*' AND Name not like '~*'")
                strMsg = strMsg & "There are " & lngObjectCount & " local tables in this database. " _
                    & vbCrLf & vbCrLf
            Else
                ' Include Local, Linked, and ODBC tables
                lngObjectCount = DCount("Name", "MSysObjects", "Type in (1,4,6) AND Name not like 'MSys*' AND Name not like '~*'")
                strMsg = strMsg & "There are " & lngObjectCount & " tables in this database " _
                    & "(including local, linked, and ODBC)." & vbCrLf & vbCrLf
            End If
            strMsg = strMsg & "The tables will be exported to a subfolder of the current database:  " _
                & strSaveDir & vbCrLf & vbCrLf
            strMsg = strMsg & "Do you want to continue?"
    
            If MsgBox(strMsg, vbYesNo + vbInformation, "Export Tables") = vbYes Then
    
                If Dir(strSaveDir, vbDirectory) = "" Then
                    MkDir strSaveDir
                End If
    
                ' Initialize and display message in status bar.
                varReturn = SysCmd(acSysCmdInitMeter, "(" & Format((lngCount) / lngObjectCount, "0%") & ")  Preparing tables", lngObjectCount)
    
                dbs.TableDefs.Refresh
                For Each td In dbs.TableDefs ' Tables
                    If (bolLocalTablesOnly = True And Len(td.Connect) = 0) _
                      Or (bolLocalTablesOnly = False) Then
    
                        If Left(td.Name, 4) <> "MSys" And Left(td.Name, 1) <> "~" Then
                            Debug.Print td.Name, td.Attributes
    
                            ' Update message in status bar.
                            varReturn = SysCmd(acSysCmdSetStatus, "(" & Format((lngCount + 1) / lngObjectCount, "0%") _
                                & ")  Exporting table: " + td.Name)
    
                            DoCmd.TransferText acExportDelim, , td.Name, strSaveDir & "Table_" & td.Name & ".txt", True
                            lngCount = lngCount + 1
    
                        End If
                    End If
                Next td
    
                'Remove the Progress Meter
                varReturn = SysCmd(acSysCmdRemoveMeter)
    
                If MsgBox("Exported " & lngCount & " object(s)." _
                    & vbCrLf & vbCrLf & "Do you want to open the destination folder: " & strSaveDir & " ? " _
                    , vbSystemModal + vbYesNo + vbInformation, "Table Size") = vbYes Then
    
                    ' Open the output folder in Windows Explorer
                    Call Shell("explorer.exe " & strSaveDir, vbNormalFocus)
                End If
            End If
        End If
    
    Exit_Sub:
        Set td = Nothing
        Set dbs = Nothing
    
        Exit Sub
    
    ErrorHandler:
    
        Debug.Print Err.Number, Err.Description
        Select Case Err
            Case "3011"
                MsgBox "Table '" & td.Name & "' could not be found or has a broken link." _
                    & vbCrLf & vbCrLf & "Link: " & td.Connect _
                    & vbCrLf & vbCrLf & "Click OK to continue.", vbExclamation, "Error 3011"
                Resume Next
            Case "75"
                ' This happens when you try to create a folder name that already exists.
                ' For this Q&D function, ignore the error.
                Resume Next
            Case Else
                MsgBox Err.Description
                Resume Next
        End Select
    
        GoTo Exit_Sub
    
    End Sub
    
        4
  •  1
  •   NOSEC    13 年前

    我使用的是Access2003,很容易获得表记录计数。表记录计数是指表大小的大小。记录越多,尺寸越大。 如何获取表记录计数?

    1. 通过Access 2003打开数据库,
    2. 单击选项卡“数据库工具”
    3. 单击“数据库文档管理工具”(可能是其他名称)。
    4. 单击“全部”和“确定”
    5. 您将看到一个新的白底页显示所有表的表信息。通过单击“txt”(在Word图标下)导出到txt
    6. 您将把TXT保存到一个文件中。我们把它命名为tableinfor.txt。
    7. 用txt编辑器打开“tableinfo.txt”。搜索关键字“recordcount”。 我想你知道哪张桌子占的空间最大。
        5
  •  1
  •   Brent B    10 年前

    您可以将每个表单独复制到单独的Access数据库中,然后比较每个表的大小。虽然它不能给出表本身的确切大小,但是每个文件的大小显示了每个表的大致大小。

    推荐文章