Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I get name of all tables of SQL Server database in C# application?

Tags:

c#

sql-server

I want to get name of all table of SQL Server database in my C# application. Is It possible? Plz tell me Solution.

like image 394
Govind Malviya Avatar asked Jun 09 '10 10:06

Govind Malviya


People also ask

How can I see all table names in SQL Server?

In MySQL, there are two ways to find the names of all tables, either by using the "show" keyword or by query INFORMATION_SCHEMA. In the case of SQL Server or MSSQL, You can either use sys. tables or INFORMATION_SCHEMA to get all table names for a database.

How do I get a list of tables in a database?

To get a list of the tables in a MySQL database, use the mysql client tool to connect to the MySQL server and run the SHOW TABLES command. The optional FULL modifier will show the table type as a second output column.

How do I find the database name and table in SQL Server?

In SQL Server, the system tables are stored per database. Hence, all is in one database, so you can just use dbname() : SELECT db_name() as DatabaseName, c.name AS ColumnName, t.name AS TableName FROM sys.


1 Answers

It is as simple as this:

DataTable t = _conn.GetSchema("Tables"); 

where _conn is a SqlConnection object that has already been connected to the correct database.

like image 75
slugster Avatar answered Sep 22 '22 15:09

slugster