SQL视图

例子

SELECT cust_name,cust_contact
FROM Customers,Orders,OrderItems
WHERE Customers.cust_id=Orders.cust_id
    AND OrderItems.order_num=Orders.order_num
    AND prod_id='RGAN01'

此查询用来检索订购了某种产品的顾客姓名,顾客联系方式。

检索其他产品的数据,要修改WHERE子句

SELECT cust_name,cust_contact
FROM ProductCustomers
WHERE prod_id='RGAN01';

ProductCustomers是一个视图,作为视图,它不含任何列或数据,仅包含一个查询。

 创建视图

CREATE VIEW ProductCustomers AS
SELECT cust_name,cust_contact,prod_id
FROM Customers,Orders,OrderItems
WHERE Customers.cust_id=Orders.cust_id
AND OrderItems.order_num=Orders.order_num

 

posted @ 2020-10-19 15:59  猫七的blog  阅读(74)  评论(0编辑  收藏  举报