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视图语句

sql视图语句_SQL视图:Replace View语句的示例语法相关推荐

  1. sqlserver修改字段长度语句_SQL Server读懂语句运行 (三) SET STATISTICS PROFILE ON

    对于语句的运行,除了执行计划本身,还有一些其他因素要考虑,例如语句的编译时间.执行时间.做了多少次磁盘读等. 这些信息对分析问题很有价值. 1 SET STATISTICS TIME ON 2 SET ...

  2. sql 纵向求和_SQL里边的求和语句怎么写

    展开全部 SQL中求和语句分为来纵自向汇总和横向汇总语bai句: 假设数据列为:duA.zhiB.C.D.E.F.G 纵向汇总dao语句: select sum(A),sum(B),sum(C),su ...

  3. mysql和sql视图连接_SQL视图和多表连接

    本篇博客关注的焦点是视图的使用以及视图和多表连接的配合.以便可以了解视图,以及更好的使用视图. 首先,还是要说明一下视图的定义:视图是基于SQL语句的结果集的可视化虚拟表,换句话说视图就是SQL查询结 ...

  4. mysql 创建外键语句_sql创建外键语句

    满意答案 Yvg5799602 2013.12.21 采纳率:57%    等级:13 已帮助:9441人 -- 创建测试主表. ID 是主键. CREATE TABLE test_main ( id ...

  5. sql limit 子句_SQL Server TOP子句概述和示例

    sql limit 子句 This article explores the SQL Server TOP clause using various examples, along the way, ...

  6. oracle查看视图定义语句_oracle视图详解

    Oracle 视图详解 一. 视图的定义 视图(view),也称虚表, 不占用物理空间,这个也是相对概念,因为视图本身的定义语句还是要存储在数据字典里的.视图只有逻辑定义.每次使用的时候,只是重新执行 ...

  7. 如何在SQL Server中创建视图

    In this article, we will learn the basics of the view concept in SQL Server and then explore methods ...

  8. mysql视图登录_mysql视图

    mysql视图机制 什么是视图 视图是一张虚拟的表,为什么是虚拟呢?因为视图与数据库中存在的表不太一样,前面我们创建的4张表都是包含数据的, 如用户信息,订单信息等,而视图则是不包含数据的,下面通过一 ...

  9. mysql 视图 中文_Mysql视图-WEB资讯专栏-DMOZ中文网站分类目录-免费收录各类优秀网站的中文网站目录....

    1.初识视图 1.视图的概念和作用 什么是视图:是从一个或多个表中导出来的表,它是一种虚拟存在的表,表的结构和数据都依赖于基本表. 作用: 简化查询语句:简化用户的查询操作,使 1.初识视图 1.视图 ...

最新文章

  1. 对称加密算法之DES介绍
  2. 我!90后!重庆女孩!在淘宝给别人改简历,年入百万!
  3. 洛谷P1016 旅行家的预算 贪心
  4. 【系统分析与设计】业务流程图绘制方法
  5. linux下c++實現簡單的生產者消費者隊列模式
  6. 文件操作工具类FileUtil
  7. OData model cache logic in gateway system
  8. UVA 11210 中国麻将
  9. 信号处理深度学习机器学习_机器学习与信号处理
  10. 假如把女生比作一种水果
  11. 使用traits技术表现迭代器类型 iterator_category
  12. 微信开发h5支付功能,配置单价和商品信息无法更新问题解决方法!
  13. Python 3.7 已上架 Microsoft Store,让你在 Windows 轻松使用 Python
  14. extern c作用_extern “C”的作用详解
  15. 表情识别(四)--多网络级联表情识别
  16. 电脑位数(32位或者64位)问题导致eclipse不能正常启动
  17. 兔子生兔子java_用Java编程计算兔子生兔子的问题
  18. 金蝶KIS商贸版即时库存表二次开发增加保质期有效期至字段列
  19. senseTime,FaceU人脸识别技术
  20. 【C++常用函数】整数转字符串itoa()

热门文章

  1. 【AI视野·今日CV 计算机视觉论文速览 第213期】Fri, 4 Jun 2021
  2. 类进阶学习目标 java 1614957028
  3. 演练 影视演员简介 0929
  4. centos安装python3.8
  5. 办公自动化-world转pdf-0223
  6. requests-session类对象-0223
  7. dj电商-数据表的设计-商品表的设计
  8. 浏览器之本地缓存存储 localStorage 和 sessionStorage的区别以及用法
  9. 《Spring实战》系列之Bean的装配-Days01
  10. 国家网络安全事件应急预案,你需要知道哪些重点