Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get table names from an MS Access Database?

Tags:

ms-access

Microsoft SQL Server and MySQL have an INFORMATION_SCHEMA table that I can query. However it does not exist in an MS Access database.

Is there an equivalent I can use?

like image 564
luntain Avatar asked Oct 14 '08 14:10

luntain


People also ask

How do I get a list of table names in Access?

Click on the View tab and check System objects. If you are using Microsoft Access 2007, 2010, 2013, or 2016, right-click on the navigation pane (just above the search box) and choose Navigation Options. Then, under display options, check Show System Objects and press OK.

What is the command to get the table names in your database?

use [db name]; To see all the tables in the db. show tables; To see database's field formats.


2 Answers

To build on Ilya's answer try the following query:

SELECT MSysObjects.Name AS table_name FROM MSysObjects WHERE (((Left([Name],1))<>"~")          AND ((Left([Name],4))<>"MSys")          AND ((MSysObjects.Type) In (1,4,6))) order by MSysObjects.Name  

(this one works without modification with an MDB)

ACCDB users may need to do something like this

SELECT MSysObjects.Name AS table_name FROM MSysObjects WHERE (((Left([Name],1))<>"~")          AND ((Left([Name],4))<>"MSys")          AND ((MSysObjects.Type) In (1,4,6))         AND ((MSysObjects.Flags)=0)) order by MSysObjects.Name  

As there is an extra table is included that appears to be a system table of some sort.

like image 78
BIBD Avatar answered Oct 13 '22 22:10

BIBD


You can use schemas in Access.

Sub ListAccessTables2(strDBPath)    Dim cnnDB As ADODB.Connection    Dim rstList As ADODB.Recordset     Set cnnDB = New ADODB.Connection     ' Open the connection.    With cnnDB       .Provider = "Microsoft.Jet.OLEDB.4.0"       .Open strDBPath    End With     ' Open the tables schema rowset.    Set rstList = cnnDB.OpenSchema(adSchemaTables)     ' Loop through the results and print the    ' names and types in the Immediate pane.    With rstList       Do While Not .EOF          If .Fields("TABLE_TYPE") <> "VIEW" Then             Debug.Print .Fields("TABLE_NAME") & vbTab & _                .Fields("TABLE_TYPE")          End If          .MoveNext       Loop    End With    cnnDB.Close    Set cnnDB = Nothing End Sub 

From: http://msdn.microsoft.com/en-us/library/aa165325(office.10).aspx

like image 25
Fionnuala Avatar answered Oct 13 '22 22:10

Fionnuala