user1709408
user1709408

Reputation: 538

How to get list of database tables in C# code (in vendor independent way)?

What are database vendor independent ways to obtain list of tables in C# code?

I heard about three:

  1. ADO .NET, IDbConnection.GetSchema("Tables")
  2. Linq, new System.Data.Linq.DataContext(IDbConnection).Mapping.GetTables(); (>=3.5, System.Data.Linq.dll).
  3. EF, Entity Framework - Get List of Tables

But this mean that somewhere there are a set of adapters for syntax of each vendor.

Is there a standard SQL syntax for this operation?

What are other ways to get list of tables in C#?

Upvotes: 2

Views: 2141

Answers (1)

Lukasz Szozda
Lukasz Szozda

Reputation: 176314

You could use ANSI standard Information Schema Views:

SELECT *
FROM INFORMATION_SCHEMA.TABLES;

Supported by: SQL Server, Postgresql, MySQL, ...

Not implemented by Oracle, DB2, SQLite,...

Upvotes: 4

Related Questions