Db2 简明教程
DB2 - Views
本章介绍了视图的介绍、创建、修改和删除视图。
This chapter describes introduction of views, creating, modifying and dropping the views.
Introduction
视图是表示存储在表中的数据的另一种方式。它不是一个真实表,并且没有永久存储。视图提供了一种查看一个或多个表中的数据的方法。它是针对结果表的命名规范。
A view is an alternative way of representing the data stored in the tables. It is not an actual table and it does not have any permanent storage. View provides a way of looking at the data in one or more tables. It is a named specification of a result table.
Creating a view
可以使用以下语法创建视图:
You can create a view using the following syntax:
Syntax:
Syntax:
db2 create view <view_name> (<col_name>,
<col_name1...) as select <cols>..
from <table_name>
Example :为 shopper.sales1 表创建视图
Example: Creating view for shopper.sales1 table
db2 create view view_sales1(id, itemname, qty, price)
as select id, itemname, qty, price from
shopper.sales1
Modifying a view
可以使用以下语法修改视图:
You can modify a view using the following syntax:
Syntax:
Syntax:
db2 alter view <view_name> alter <col_name>
add scope <table_or_view_name>
Example :[向现有视图“view_sales1”添加新表列]
Example: [To add new table column to existing view ‘view_sales1’]
db2 alter view view_sales1 alter id add
scope shopper.sales1