Enumerating Database tables programmatically in SQLServer or oracle

C

Cless

Hi everyone,

Given a connection string, is there a way to retrieve all database
objects from a database. I already know through the MSDN documentation
of .NET of how to enumerate all database instances of sqlserver 2000
and up from a local network, but unfortunately I am yet to find an
example of how to get all tables from a given database.


Regards,

cless
 
L

Lasse Vågsæther Karlsen

Cless said:
Hi everyone,

Given a connection string, is there a way to retrieve all database
objects from a database. I already know through the MSDN documentation
of .NET of how to enumerate all database instances of sqlserver 2000
and up from a local network, but unfortunately I am yet to find an
example of how to get all tables from a given database.


Regards,

cless

Well, you typically issue queries against system schema tables in the
database, which contain information about which user tables are present.

The names and contents of those tables tends to vary from one database
engine vendor to the next, so you might not be able to write one piece
of code that works on all types of connection.

In SQL Server 2005, look at the INFORMATION_SCHEMA schema and see what
it contains.
 
A

Arne Vajhøj

Cless said:
Given a connection string, is there a way to retrieve all database
objects from a database. I already know through the MSDN documentation
of .NET of how to enumerate all database instances of sqlserver 2000
and up from a local network, but unfortunately I am yet to find an
example of how to get all tables from a given database.

There are lots of ways but none that will work with every database.

Databases that have decent ANSI SQL support:

SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE
TABLE_SCHEMA='xxxx' AND TABLE_TYPE='Base table'

OLE DB:

OleDbConnection GetOleDbSchemaTable

Database specific commands:

SQLServer:

SP_TABLES

MySQL:

SHOW TABLES

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top