开发者

Create View that references view not created yet

开发者 https://www.devze.com 2023-02-23 06:54 出处:网络
I have a schema extraction tool for SQL & Oracle which then tries to create a new database from the schema of another one.

I have a schema extraction tool for SQL & Oracle which then tries to create a new database from the schema of another one.

I have encountered a problem with SQL at the moment (most likely exists in Oracle) tha开发者_JAVA技巧t when it tries to do something like

CREATE VIEW TestView
SELECT * FROM AnotherViewNotCreated

it errors.

I thought using the EXEC command in SQL would work but it also complains that the view does not exist.

Is there a way I can create the views even if they reference other views that do not exist yet?

UPDATE: I've noticed if you Generate Scripts from SQL it outputs the order of view creation in an order that seems to suggest it knows which ones should be created first to prevent reference issues. Wonder how it knows?


How could you create the view if it calls a view that doesn't exist yet? You simply have to run scripts in dependency order.

I would not recommend using views that call other views for performance reasons. We nearly lost a multi-million dollar client because some application developer thought this was a good idea. It worked fine until there were large amounts of data and then the sytem slowed to a crawl. Views that call other views, espcially when they go more than one level down, can be particularly diffiult to troubleshoot and maintain. I would really think about whether this is a good idea.


I don't think you can. This thread suggests you "fake" the table first, which may work for you, but you may need to re-create the dependent view when the real one is available.

0

精彩评论

暂无评论...
验证码 换一张
取 消