So che questo è un vecchio post ma ho una soluzione basata sulla mia esperienza con la stessa domanda. La mia soluzione è di esportare tutte le tabelle in file di testo. La dimensione di ogni file di testo è approssimativamente proporzionale alla quantità di spazio utilizzata nel file mdb/accdb.
Il codice seguente creerà una sottocartella "temp_table_size" nella cartella del database corrente ed esporterà tutte le tabelle ad essa. È possibile passarlo un parametro per elaborare solo le tabelle locali. Al termine, indica quante tabelle sono state esportate e chiede se si desidera aprire la cartella. Ordina questa cartella in base alle dimensioni e identificherai rapidamente i colpevoli. Uso questa routine per trovare tabelle che potrei aver dimenticato di cancellare prima della distribuzione o per aiutarmi a capire dove si trovano i grandi tavoli quando eredito il database di qualcun altro.
Per rendere questa routine ancora più utile per me, ho aggiunto questo codice a un componente aggiuntivo di Access in modo da poterlo eseguire su qualsiasi database. Questo componente aggiuntivo dispone anche di funzionalità per esportare tutti gli altri oggetti di Access in modo da poter vedere quali moduli/report occupano spazio nel database. Forse troverò un posto per condividerlo se c'è qualche interesse.
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
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
Grazie per aver sottolineato quello strumento. Sfortunatamente, lo strumento mi dice solo che la maggior parte dello spazio è occupato dai dati "Memo/OLE", ma non mi dice quale tabella contiene quanti dati "Memo/OLE". Invece, tutti i dati "Memo/OLE" sono raggruppati sotto un'intestazione "## non correlata direttamente a una tabella ##". La compressione del database non aiuta; il file MDB non si riduce affatto. - Frank –
Come soluzione temporanea, ora ho importato il database MDB su un server SQL e, in SQL Server Management Studio, ho aggiunto la colonna "Spazio dati utilizzato" alla vista elenco. Questo mi dice quale tabella usa quanto spazio. Usando questa procedura, ho scoperto che una singola tabella nel mio database utilizza quasi tutto lo spazio su disco. –
I dati memo/OLE non sono effettivamente memorizzati nel record. Invece c'è un puntatore a una pagina in cui ogni Memo/OLE è effettivamente memorizzato. Quindi non è in realtà con il record. Tuttavia esiste un codice VBA che è possibile eseguire per determinare quali tabelle hanno campi Memo/OLE e quanti di essi esistono. Hmm, e probabilmente la dimensione di ciascuno, ma dovrei soffermarmi un po 'su questo. Anche se ora sembra aver capito quale tavolo occupa lo spazio. –