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

情到浓时终转凉″ 提交于 2019-12-11 14:44:28

问题


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?


回答1:


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



回答2:


EXEC sp_MSforeachtable N'SELECT * FROM ?'


来源:https://stackoverflow.com/questions/8329661/in-sql-server-i-want-to-use-the-same-query-for-all-the-tables-in-a-database

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!