.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> Windows Application >> Post New QuestionBookmark and Share Subscribe to Forum

Read table name from Database

Posted By: Madhu Gowda     Posted Date: May 04, 2011    Points:5   Category :Windows Application
i want to read just table name from sql database in C# windows application..
is there any built in method to read that table name
please guide me..

thanks in advance.....

Responses
Author: Dhiraj Ranka             
Posted Date: May 05, 2011     Points: 20   

Hi,

This is very simple and can be achieved using system table sys.tables.

USE <YourDBName>
GO
SELECT *
FROM sys.Tables
GO


This will return all the tables in the database which user have created.

Hope this helps.

Thanks & Regards,
Dhiraj Ranka
http://www.twitter.com/dhirajranka | http://www.dhirajranka.com
Author: kamlesh             
Posted Date: May 05, 2011     Points: 20   

DECLARE @TableName sysname
SELECT @TableName=MIN(TABLE_NAME) from INFORMATION_SCHEMA.TABLES where TABLE_TYPE ='BASE TABLE'
WHILE @TableName IS NOT NULL
BEGIN
--your other code

SELECT @TableName=MIN(TABLE_NAME) from INFORMATION_SCHEMA.TABLES where TABLE_TYPE ='BASE TABLE'
AND TABLE_NAME > @TableName

END



or



Another statement:

select * from sys.tables

Thanks And Regards.
Kamlesh Nikam
Author: Maverick             
Posted Date: May 09, 2011     Points: 20   

Hello,

Use INFORMATION_SCHEMA.TABLES or sys.tables to do it.

Hope it helps

Thanks,
Maverick
Author: Narayanan             
Posted Date: March 15, 2012     Points: 20   


Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend