C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » SQL Server »

Query to retrieve table names


Posted Date: 07 Nov 2009      Posted By: Pavan      Member Level: Bronze     Points: 1   Responses: 4



I want a query to retrieve all the tables names in the database
If i am using the data base College in that if it have the tables
First Year
Second Year
Third Year
Fourth Year


i want the query to retrieve this 4 table Names from my database College





Responses

Author: Reach2Shaik    07 Nov 2009Member Level: GoldRating: 3 out of 53 out of 53 out of 5     Points: 3

Hi Pavan,

Try this

SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=Test;Integrated Security=True");
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter("Select Name from sysobjects where xtype=" + "'u'", conn);
da.Fill(ds);
DataTable dt = ds.Tables[0];


Don't forget to rate this answer, if it is helpful...
Regards Shaik



Author: Shivraj Singh Rajawat    07 Nov 2009Member Level: BronzeRating: 2 out of 52 out of 5     Points: 2

SELECT name
FROM dbo.sysobjects
WHERE xtype = 'U'



Author: Shameer    08 Nov 2009Member Level: SilverRating: 2 out of 52 out of 5     Points: 2

string connectionString = "...";
DataTable tables = new DataTable("Tables");
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand command = connection.CreateCommand();
command.CommandText = "select table_name as Name from
INFORMATION_SCHEMA.Tables where TABLE_TYPE =
'BASE TABLE'";
connection.Open();
tables.Load(command.ExecuteReader(
CommandBehavior.CloseConnection));
}



Author: Anish Nair    09 Nov 2009Member Level: SilverRating: 2 out of 52 out of 5     Points: 2

select * from sysobjects where type = 'U' - To see list of user tables
select * from sysobjects where type = 'S' - To see list of system tables
select * from sysobjects where type = 'P' - To see list of stored procedures
select * from sysobjects where type = 'V' - To see list of views

Cheer's
Be Positive..
Anish..
http://www.dotnetsourcecodes.blogspot.com/



Post Reply
You must Sign In to post a response.
Next : Joining table
Previous : 70-441/.Net 3.5
Return to Discussion Forum
Post New Message
Category: SQL Server

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use