In SQL Server, I want to use the same query for all the tables in a database

I need to find a way to perform the same query to all the tables in an specific database.

For example, if my database DB has the tables Table1, Table2, Table3, Table4 and Table5, I want to perform the query

SELECT * FROM <All 5 Tables>

Anyone knows how to do this?

Answers


USE [DB]
exec sp_msforeachtable 'SELECT * FROM ?'

Need Your Help

make blank row appear 0 in ms sql

sql sql-server sql-server-2005

I have a table containing Remarks as a column. Now i have to display the data inside remarks as 0 if the row is blank i.e empty but not Null. Please give me a query that will solve my problem in MS...

Ruby converting String to File for uploading to FTP

ruby csv ftp stringio

Currently we have a method that returns a string with a formatted CSV file.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.