owl*_*owl 3 sql sql-server stored-procedures
如何查看数据库中所有存储过程(+视图和函数)使用的所有列和表的列表。
例子:
create procedure proc as
select tab1.a,tab2.d,tab2.e
from tab1
join tab2 on tab1.b = tab2.b
where tab1.c = 'filter'
end
Run Code Online (Sandbox Code Playgroud)
输出:
tab1.a
tab1.b
tab1.c
tab2.b
tab2.d
tab2.e
Run Code Online (Sandbox Code Playgroud)
我需要查看数据库中任何代码引用的所有列。谢谢你。
欢迎提出意见。
create proc usp_test1
as
begin
select name,object_id from test
end
create proc usp_test2
as
begin
select * from test1
end
Run Code Online (Sandbox Code Playgroud)
执行下面的代码给了我
SELECT DISTINCT
O.name SP_Name,T.name Table_Name,c.name Field_Name
FROM sys.sysdepends D
JOIN sys.sysobjects O ON O.id = D.id
JOIN sys.sysobjects T ON T.id = D.depid
JOIN sys.columns C ON C.column_id=d.depnumber
and C.object_id=D.depID
WHERE O.xtype = 'P'
SP_Name Table_Name Field_Name
usp_test1 test name
usp_test1 test object_id
usp_test2 test1 create_date
usp_test2 test1 is_ms_shipped
usp_test2 test1 is_published
usp_test2 test1 is_schema_published
usp_test2 test1 modify_date
usp_test2 test1 name
usp_test2 test1 object_id
usp_test2 test1 parent_object_id
usp_test2 test1 principal_id
usp_test2 test1 schema_id
usp_test2 test1 type
usp_test2 test1 type_desc
Run Code Online (Sandbox Code Playgroud)
参考资料: http : //www.sqlservercentral.com/Forums/Topic1060325-149-1.aspx
| 归档时间: |
|
| 查看次数: |
2539 次 |
| 最近记录: |