简体   繁体   English

逆向工程视图

[英]Reverse Engineering a View

I was asked how to reverse engineer a view so it can be determined what columns and table were used in the sql query to produce the view . 我被问到如何对视图进行逆向工程,以便可以确定在sql查询中使用了哪些列和表来生成视图。 So say view 1 was constructed from the following 10 tables and 43 columns . 可以说,视图1是由以下10个表和43列构成的。 Is this even possible in sql server 2005 ? 在sql server 2005中甚至可能吗?

Use sp_helptext 使用sp_helptext

exec sp_helptext 'your_view'

Edit 编辑

What you want is to find out what dependencies your view has. 您想要的是找出您的视图具有哪些依赖项。 You can use sp_depends to do that, but it will only get you the table dependencies and not the columns. 您可以使用sp_depends来执行此操作,但它只会为您提供表相关性,而不会为您提供列。

exec sp_depends 'your_view'

In order to find out the columns you will probably have to code some kind of SQL parser to extract the columns being used from the Create View statement you recovered with sp_helptext. 为了找出列,您可能必须编写某种SQL解析器,以从使用sp_helptext恢复的Create View语句中提取正在使用的列。

You can try using a ReGex to extract the info you want or if you want a big and fancier gun you can try Irony which has a built in Sql Lexic. 您可以尝试使用ReGex提取所需的信息,或者如果您想要更大而更高级的枪,则可以尝试具有内置Sql Lexic的Irony

Yes, in SSMS choose your database -> views -> right click -> script as CREATE . 是的,在SSMS中选择database -> views ->右键单击-> script as CREATE

If you want to decode a view on another database, you have no access to (eg interface) - than this is not possible. 如果要解码另一个数据库上的视图,则无权访问(例如,接口),否则将无法访问。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM