如何通过 System i Navigator 更改或编辑 DB2 中的视图?我不知道怎么做,因为它会删除建立在它上面的其他视图。
无法使用 iSeries Navigator 更改视图。但是,如果您愿意使用 SQL 语句并且您使用的是 v7.1 或更高版本,则可以使用新的“CREATE OR REPLACE VIEW”命令:SQL CREATE OR REPLACE 语法。
这将允许您更改现有视图,而无需先删除相关对象。例如,考虑一个名为“VIEW2”的视图,它使用来自“VIEW1”的名为“DESC”的列。您可以使用以下命令向“VIEW1”添加一列而不影响“VIEW2”:
CREATE OR REPLACE VIEW MYSCHEMA.VIEW1 AS
SELECT DESC, NEWCOL FROM MYSCHEMA.MYTABLE;
Run Code Online (Sandbox Code Playgroud)
同样,您可以从“VIEW1”中删除一列而不影响其他视图。唯一的限制是您不能删除另一个视图(或函数、别名等)使用的列。如果您尝试删除另一个视图所依赖的列,您将收到一条错误消息。
使用“REPLACE”方法还将保留所有权限/安全约束。
It should be noted that a more ideal method would be to automate the creation of views/functions/procs/aliases/etc via scripts. This would allow you to drop and recreate dependent objects in a consistent manner. This presumes some manner of automation around your database management, and may present issues if you have a very large number of dependent objects (of if you have a large number of indexed views.) The biggest risk with having a large number of "REPLACE" scripts is that they will be applied incorrectly, either by not applying one of the scripts or by applying them in the wrong order.
| 归档时间: |
|
| 查看次数: |
5321 次 |
| 最近记录: |