Add multi tables view describe.

This commit is contained in:
mba1398 2024-05-26 15:42:56 +08:00 committed by GitHub
parent 9ac543522a
commit 4689f38745
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 6 additions and 3 deletions

View File

@ -112,16 +112,19 @@ INSERT INTO shop_product (shop_id, shop_name, product_id, quantity) VALUES ('000
INSERT INTO shop_product (shop_id, shop_name, product_id, quantity) VALUES ('000D', '福冈', '0001', 100); INSERT INTO shop_product (shop_id, shop_name, product_id, quantity) VALUES ('000D', '福冈', '0001', 100);
``` ```
我们在product表和shop_product表的基础上创建视图。 **创建多表视图和核心语句和多表关联查询语句相同,只不过多了 `CREATE VIEW VIEW_NAME AS`。**
下面,我们在 product 表和 shop_product 表的基础上创建视图。
```sql ```sql
CREATE VIEW view_shop_product(product_type, sale_price, shop_name) CREATE VIEW view_shop_product(product_type, sale_price, shop_name)
AS AS
SELECT product_type, sale_price, shop_name SELECT product_type, sale_price, shop_name
FROM product, FROM product
shop_product JOIN shop_product
WHERE product.product_id = shop_product.product_id; WHERE product.product_id = shop_product.product_id;
``` ```
创建的视图如下图所示 创建的视图如下图所示
![图片](./img/ch03/ch03.04view4.png) ![图片](./img/ch03/ch03.04view4.png)