By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,281 Members | 2,216 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,281 IT Pros & Developers. It's quick & easy.

Enumerating Database tables programmatically in SQLServer or oracle

P: n/a
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
Jun 27 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Cless wrote:
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.

--
Lasse Vågsæther Karlsen
mailto:la***@vkarlsen.no
http://presentationmode.blogspot.com/
PGP KeyID: 0xBCDEA2E3
Jun 27 '08 #2

P: n/a
Cless wrote:
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
Jun 27 '08 #3

P: n/a


Thank you very much for your reply.
Jun 27 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.