Click here to Skip to main content
15,867,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
USE datamigrationtest SELECT * FROM sys.Tables;


this is my query i am using this query in sql2008r2 and window form application .
This query is work for some database and not working some database so wt i do to resolve thsi iss i want all table name from database datamigrationtest but i am get error Invalid object name 'sys.Tables'. what is an issue pls help me
Posted
Comments
Vedat Ozan Oner 13-Feb-14 4:26am    
are you sure that you have database 'datamigrationtest' on each server you connect? if you don't, yours or other queries will fail.

Dear All thank you for support

before(query not work)

SQL
string str = "USE " + strintTable + " SELECT * FROM sys.Tables";


after query work
SQL
string str = "USE " + strintTable + " SELECT * FROM sys.tables";
 
Share this answer
 
Use this..
SQL
EXEC sp_tables @table_type = "'TABLE'"
 
Share this answer
 
Comments
Arjunwalmiki 13-Feb-14 4:34am    
i want all table name from datamigrationtest (database)? just like
string str = "USE " + strintTable + " SELECT * FROM sys.Tables";
Arjunwalmiki 13-Feb-14 4:38am    
your query is working fine EXEC sp_tables @table_type = "'TABLE'" but how can set it in this query string str = "USE " + strintTable + " SELECT * FROM sys.Tables";
V5709 13-Feb-14 5:00am    
Look at my new solution ie. solution 5
 
Share this answer
 
SQL Server 2005 or 2008:
SQL
SELECT * FROM information_schema.tables

SQL Server 2000:
SQL
SELECT * FROM sysobjects WHERE xtype='U'
 
Share this answer
 
Comments
Arjunwalmiki 13-Feb-14 4:37am    
SELECT * FROM information_schema.tables thsi query is not working
im using sqlserver2008 R2.its working well

SQL
SELECT * FROM datamigrationtest.sys.Tables;
 
Share this answer
 
Comments
Arjunwalmiki 13-Feb-14 4:36am    
SELECT * FROM datamigrationtest.sys.Tables; this query is not working
try this.

SQL
string str=  "USE DbPerson;";
              str += "SELECT table_name FROM information_schema.tables WHERE table_type = 'base table';";
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900