Be aware that you cannot be sure you have extracted all of a table's schema even when using both ADO (which you need for CHECK
constraints, WITH COMPRESSION
, etc) and ACEDAO (which you need for complex data types, etc).
Here's an example of such a table:
Sub CantGetCheck()
On Error Resume Next
Kill Environ$("temp") & "\DropMe.mdb"
On Error GoTo 0
Dim cat
Set cat = CreateObject("ADOX.Catalog")
With cat
.Create _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & _
Environ$("temp") & "\DropMe.mdb"
With .ActiveConnection
Dim Sql As String
Sql = _
"CREATE TABLE Test " & _
"(" & _
" data_col INTEGER NOT NULL, " & _
" CONSTRAINT data_col__be_positive " & _
" CHECK (data_col >= 0), " & _
" CONSTRAINT data_col__values " & _
" CHECK ( " & _
" data_col = 0 OR data_col = 1 OR data_col = 2 " & _
" OR data_col = 3 OR data_col = 4 OR data_col = 5 " & _
" OR data_col = 6 OR data_col = 7 OR data_col = 8 " & _
" OR data_col = 9 OR data_col = 10 OR data_col = 11 " & _
" OR data_col = 12 OR data_col = 13 OR data_col = 14 " & _
" OR data_col = 15 OR data_col = 16 OR data_col = 17 " & _
" OR data_col = 18 OR data_col = 19 OR data_col = 20 " & _
" ) " & _
");"
.Execute Sql
Dim rs
' 5 = adSchemaCheckConstraints
Set rs = .OpenSchema(5)
MsgBox rs.GetString
End With
Set .ActiveConnection = Nothing
End With
End Sub
The output shows that while the definition for the constraint named data_col__be_positive
can indeed be extracted, the data_col__values
definition cannot (because it exceeds 255 characters).
So really the solution is to always retain the code you used to create and subsequently alter the table. For me, using SQL DDL scripts for the purpose make a lot of sense (I do not need the few features that are not creatable via DDL).