RE: How to get tables/views/columns in ODBC (& OleDb)
- From: jialge@xxxxxxxxxxxxxxxxxxxx ("Jialiang Ge [MSFT]")
- Date: Mon, 25 Aug 2008 07:49:21 GMT
Hello Dave,
The collection of DB schema information VARIES in different providers and
drivers. The common schema collection that are supported by all the managed
providers is documented at:
Understanding the Common Schema Collections
http://msdn.microsoft.com/en-us/library/ms254501(VS.80).aspx
But this collection does not include your requested information like all
user tables in a DB. To get the detailed schema info, we would need to
first decide the DB (SQL Server/Oracle/Access, etc) and the provider
(OLEDB/ODBC/ Microsoft .NET Framework Data Provider). For each combination,
we have provider-specific schema collections:
Understanding the Provider-Specific Schema Collections
http://msdn.microsoft.com/en-us/library/ms254969(VS.80).aspx
Some of them provide restricted collection of info; some provide the
details that may meet our needs.
So back to your questions:
1. how do I get the following from ODBC and OleDb in a way that will work
on all databases
This is hard to do because each provider supplies different set of schema
info.
2. how do I do it for Sql Server 2000, Sql Server 2005, and Access
OLEDB provider for SQL server may better fit the need.
(see "Microsoft SQL Server OLEDB Provider" and "Microsoft Jet OLEDB
Provider" sections in the article
http://msdn.microsoft.com/en-us/library/ms254969(VS.80).aspx).
1) Enumerate all user tables in a database.
We can call conn.GetSchema("Tables"); and filter the outputs by
TABLE_TYPE=="TABLE"
2) Enumerate all tables (user & system) in a database.
We can call conn.GetSchema("Tables"); and filter the outputs by
TABLE_TYPE=="TABLE" OR TABLE_TYPE=="SYSTEM TABLE"
3) Enumerate all user views in a database.
We can call conn.GetSchema("Tables"); and filter the outputs by
TABLE_TYPE=="VIEW"
4) Enumerate all views (user & system) in a database.
We can call conn.GetSchema("Tables"); and filter the outputs by
TABLE_TYPE=="VIEW" OR TABLE_TYPE=="SYSTEM VIEW"
5) Enumerate all columns in a table or view.
We can call conn.GetSchema("Columns"); and filter the outputs by
TABLE_NAME=="our table/view name"
6) For a column, get it's data type.
The DATA_TYPE field of question 5) provides the data type info of the
column.
7) Enumerate all user stored procedures in a database
8) Enumerate all stored procedures (user & system) in a database.
We can call conn.GetSchema("Procedures"); to get all the stored procedures.
As far as I know, there's no strict criteria to distinguish the user/system
stored procedure. A possible solution is to filter by SP name because all
the system SPs starts with "dt_" or "sp_".
9) For a stored procedure, get all parameters and their data type.
conn.GetSchema("ProcedureParameters"); and filter the outputs by
PROCEDURE_NAME="our procedure name"
10) For all objects - get the description of it in the metadata.
Do you mean MetaDataCollections?
http://msdn.microsoft.com/en-us/library/ms254501(VS.80).aspx
Apart from the above, OLEDB provider has an additional set of methods to
retrieve the schema info:
http://support.microsoft.com/kb/309681/en-us
If you have any other questions or concerns, please DON'T hesitate to tell
me.
Regards,
Jialiang Ge (jialge@xxxxxxxxxxxxxxxxxxxx, remove 'online.')
Microsoft Online Community Support
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@xxxxxxxxxxxxxx
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://support.microsoft.com/select/default.aspx?target=assistance&ln=en-us.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
.
- Follow-Ups:
- Re: How to get tables/views/columns in ODBC (& OleDb)
- From: David Thielen
- Re: How to get tables/views/columns in ODBC (& OleDb)
- References:
- How to get tables/views/columns in ODBC (& OleDb)
- From: David Thielen
- How to get tables/views/columns in ODBC (& OleDb)
- Prev by Date: Is there a standard way to do the following in ODBC and/or OleDb
- Next by Date: RE: Is there a standard way to do the following in ODBC and/or OleDb
- Previous by thread: How to get tables/views/columns in ODBC (& OleDb)
- Next by thread: Re: How to get tables/views/columns in ODBC (& OleDb)
- Index(es):
Relevant Pages
|