SQL statement for returning a list of all tables ***SOLVED***

joohang

Lifer
Oct 22, 2000
12,340
1
0


<< A list of just the table names or all the columns also? >>


Just the table names. Is there such a thing?
 

manly

Lifer
Jan 25, 2000
13,086
3,850
136
I don't think there's an ANSI SQL way of doing this, but I could be wrong.

Each RDBMS' data dictionaries are proprietary, so there couldn't be a standard query of the database metadata.

In Sybase SQL Server, there's a stored procedure that does it... sp_tables I think. My hunch is most other databases would do it similarly.
 

joohang

Lifer
Oct 22, 2000
12,340
1
0


<< I don't think there's an ANSI SQL way of doing this, but I could be wrong.

Each RDBMS' data dictionaries are proprietary, so there couldn't be a standard query of the database metadata.

In Sybase SQL Server, there's a stored procedure that does it... sp_tables I think. My hunch is most other databases would do it similarly.
>>


Interesting. I heard about something similar with MS SQL Server but not sure exactly what it was.

I'm doing this with an Access database. It looks like there is no way to do it through ANSI SQL so I'm using ADO.NET. The idea is to simply populate a listbox with a list of tables in the database.

I might put up some sample code here later on. I think I figured it out. :)
 

joohang

Lifer
Oct 22, 2000
12,340
1
0
Here it is, in case you are interested.

private void ListTables()
{
loadDataConnection = new OleDbConnection();
loadDataConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + loadDatabaseTextBox.Text;

try
{
loadDataConnection.Open();

// Get the Tables Schema and load to a Data Table
DataTable tablesDataTable = loadDataConnection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] {null, null, null, "TABLE"});

tableListBox.DataSource = tablesDataTable;
tableListBox.DisplayMember = "TABLE_NAME";

loadDataConnection.Close();
}
catch(Exception ex)
{
MessageBox.Show("Exception: " + ex.Message);
}
}