tags:

views:

74

answers:

3

Can any one tell me that how to get names of all tables of a database using asp.net

+1  A: 

You didn't mention which database engine you are using. On SQL Server, you can query the sysobjects table and filter for objects with type U:

SELECT name FROM sysobjects WHERE type = 'U'
Mehrdad Afshari
+3  A: 

A newer method on SQL Server is to use the INFORMATION_SCHEMA Views to get the information:

SELECT table_name FROM INFORMATION_SCHEMA.Tables WHERE table_type='BASE TABLE'

This particular view also includes Views in its list of tables, which is why you need the where clause.

patmortech
+1. This is a better and more portable method than mine, although it's a little longer.
Mehrdad Afshari
A: 

In case you are interested in the MySQL way to achieve this, you can use

DESCRIBE tableName;
Davide Gualano