sql视图语句_SQL视图:Replace View语句的示例语法

sql视图语句

A View is a database object that presents data from in one or more tables. The same SQL statement used to create a view can also be used to replace an existing view.

视图是一个数据库对象,用于显示一个或多个表中的数据。 用于创建视图的相同SQL语句也可以用于替换现有视图。

This guide will update (replace) the existing view “programming-students-v” with one that is slightly different and has a different name.

本指南将使用略有不同且名称不同的视图来更新(替换)现有视图“ programming-students-v”。

Safety tip: always backup the schema before making changes to it.

安全提示:始终在更改架构之前备份架构。

一般语法 (General sytax)

CREATE OR REPLACE VIEW view_name AS
SELECT column1, column2, ...
FROM table_name
WHERE condition;

SQL用于创建视图和当前数据 (SQL Used to create the view and the current data)

create view `programming-students-v` as
select FullName, programOfStudy 
from student 
where programOfStudy = 'Programming';
select * from `programming-students-v`;

Current Data:

当前数据:

+-----------------+----------------+
| FullName        | programOfStudy |
+-----------------+----------------+
| Teri Gutierrez  | Programming    |
| Spencer Pautier | Programming    |
| Louis Ramsey    | Programming    |
| Alvin Greene    | Programming    |
| Sophie Freeman  | Programming    |
+-----------------+----------------+
5 rows in set (0.00 sec)

A list of the existing views:

现有视图的列表:

SHOW FULL TABLES IN fcc_sql_guides_database WHERE TABLE_TYPE LIKE 'VIEW';
+-----------------------------------+------------+
| Tables_in_fcc_sql_guides_database | Table_type |
+-----------------------------------+------------+
| programming-students-v            | VIEW       |
| students-contact-info_v           | VIEW       |
| students_dropme_v                 | VIEW       |
+-----------------------------------+------------+
3 rows in set (0.00 sec)

更换视图 (Replacing the view)

create or replace view `programming-students-v` as
select FullName, programOfStudy, sat_score 
from student 
where programOfStudy = 'Programming';
select * from `programming-students-v`;

Note: the view now shows the sat_score.

注意:该视图现在显示sat_score。

+-----------------+----------------+-----------+
| FullName        | programOfStudy | sat_score |
+-----------------+----------------+-----------+
| Teri Gutierrez  | Programming    |       800 |
| Spencer Pautier | Programming    |      1000 |
| Louis Ramsey    | Programming    |      1200 |
| Alvin Greene    | Programming    |      1200 |
| Sophie Freeman  | Programming    |      1200 |
+-----------------+----------------+-----------+

Note: the list of views hasn’t change, our view is replaced.

注意:视图列表未更改,我们的视图已替换。

mysql>  SHOW FULL TABLES IN fcc_sql_guides_database WHERE TABLE_TYPE LIKE 'VIEW';
+-----------------------------------+------------+
| Tables_in_fcc_sql_guides_database | Table_type |
+-----------------------------------+------------+
| programming-students-v            | VIEW       |
| students-contact-info_v           | VIEW       |
| students_dropme_v                 | VIEW       |
+-----------------------------------+------------+
3 rows in set (0.00 sec)

As with all of these SQL things there is MUCH MORE to them than what’s in this introductory guide.

与所有这些SQL事物一样,它们比本入门指南中的内容要多得多。

I hope this at least gives you enough to get started. Please see the manual for your database manager and have fun trying different options yourself.

我希望这至少能给您足够的入门。 请参阅数据库管理员的手册,并尝试自己尝试其他选项,这很有趣。

翻译自: https://www.freecodecamp.org/news/the-sql-replace-view-statement-example-syntax/

sql视图语句

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值