查询以返回数据库中的所有表 [英] Query to return all tables in db
本文介绍了查询以返回数据库中的所有表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
一口气执行所有存储过程时,我需要一个查询以返回所有表.
假设我有5张桌子
和5个表中的两个表关联的2 sp
现在我在执行sp1和sp2时需要一个查询,它返回所有表,有人可以有任何想法吗?
Hi,
I need a query to return all the tables when i execute all the stored procedure in one go .
Suppose i have 5 tables
and 2 sp associated with the two tables among five tables
now i need a query when i execute sp1 and sp2 it return all the tables , can anybody have any idea ?
推荐答案
您是否正在寻找类似的东西:
Hi,
Are you looking for something like:
WITH ProcTablesDetails AS (
SELECT o.name AS Procedure_Name, oo.name AS Table_Name,
ROW_NUMBER() OVER(PARTITION BY o.name,oo.name ORDER BY o.name,oo.name) AS Details
FROM sysdepends d
INNER JOIN sysobjects o ON o.id=d.id
INNER JOIN sysobjects oo ON oo.id=d.depid
WHERE o.xtype = 'P')
SELECT Procedure_Name, Table_Name FROM ProcTablesDetails
WHERE Details = 1
ORDER BY Procedure_Name,Table_Name
祝一切顺利.
--Amit
All the best.
--Amit
SELECT Name
FROM sys.Tables
感谢回复,但这不是我在寻找....
我想像
执行
exec spname1,spname2,spname3
GO
执行上述语句后,它返回
sp_name表名
spname1 table3
spname2 table1
spname2 table4
Thanks for reply , but it is not i am looking for ....
I want to execute like
exec spname1 , spname2 , spname3
GO
On executing above statement it return
sp_name Table_name
spname1 table3
spname2 table1
spname2 table4
这篇关于查询以返回数据库中的所有表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文