mysql创建视图sql

什么是SQL视图? (What is a View in SQL?)

A View is a database object that presents data existing in one or more tables. Views are used in a similar way to tables, but they don’t contain any data. They just “point” to the data that exists elsewhere (tables or views, for example).

视图是一个数据库对象,它显示一个或多个表中存在的数据。 视图的使用方式与表相似,但是它们不包含任何数据。 它们只是“指向”其他地方存在的数据(例如表或视图)。

我们为什么喜欢它们? (Why do we like them?)

  • Views are a way to limit the data presented. For example, the human resources department data filtered to only present sensitive information. Sensitive information in this case could be social security numbers, sex of employee, payrate, home address, etc.视图是一种限制呈现数据的方法。 例如,人力资源部门数据被过滤为仅显示敏感信息。 在这种情况下,敏感信息可能是社会保险号,员工性别,薪资,家庭住址等。
  • Complex data across more than one table can be combined into a single “view.” This can make life easier for your business analysts and programmers.可以将多个表中的复杂数据合并为一个“视图”。 这可以使您的业务分析师和程序员的工作更加轻松。

重要安全提示 (Important Safety Tips)

  • Views are managed by the system. When data in the related tables are changed, added, or updated, the View is updated by the system. We want to use these only when needed to manage use of system resources.视图由系统管理。 更改,添加或更新相关表中的数据时,系统将更新视图。 我们只想在需要管理系统资源使用时使用它们。
  • In MySQL, changes to the table design (that is, new or dropped columns) made AFTER a view is created are not updated in the view itself. The view would have to be updated or recreated.在MySQL中,创建视图后对表设计(即新列或删除的列)的更改不会在视图本身中更新。 该视图将必须更新或重新创建。
  • Views are one of the four standard database object types. The others are tables, stored procedures, and functions.视图是四种标准数据库对象类型之一。 其他是表,存储过程和函数。
  • Views can usually be treated as you would a table, but updates are limited or not available when the view contains more than one table.视图通常可以像对待表一样对待,但是当视图包含多个表时,更新受到限制或不可用。
  • There are many other details about views that are beyond the scope of this introductory guide. Spend time with your database managers manual and have fun with this powerful SQL object.关于视图的许多其他详细信息超出了本入门指南的范围。 花时间阅读数据库管理器手册,并使用这个功能强大SQL对象带来的乐趣。

Create View语句的语法(MySQL) (Syntax of the Create View Statement (MySQL))

CREATE[OR REPLACE][ALGORITHM = {UNDEFINED | MERGE | TEMPTABLE}][DEFINER = { user | CURRENT_USER }][SQL SECURITY { DEFINER | INVOKER }]VIEW view_name [(column_list)]AS select_statement[WITH [CASCADED | LOCAL] CHECK OPTION]

This guide will cover this part of of the statement…

本指南将涵盖声明的这一部分……

CREATEVIEW view_name [(column_list)]AS select_statement

从学生表创建示例视图 (Sample View creation from the student tables)

Notes:

笔记:

  • The name of the view has a “v” at the end. It’s recommended that the view name indicate that it’s a view in some way to make life easier for programmers and database administrators. Your IT shop should have its own rules on naming objects.视图名称的末尾带有“ v”。 建议视图名称以某种方式表明它是一个视图,以使程序员和数据库管理员的工作更加轻松。 您的IT部门应在命名对象方面有自己的规则。
  • The columns in the view are limited by the SELECT and the rows of data by the WHERE clause.视图中的列受SELECT限制,数据行受WHERE子句限制。
  • the ”`” character around the view names is required because of the ”-” in the names. MySQL reports an error without them.由于名称中的“-”,因此需要在视图名称周围添加“`”字符。 没有它们,MySQL报告一个错误。
create view `programming-students-v` as
select FullName, programOfStudy
from student
where programOfStudy = 'Programming';select * from `programming-students-v`;

使用视图合并多个表中的数据的示例 (Sample of using a View to combine data from more than one table)

A Student demographics table was added to the database to demonstrate this usage. This view will combine these tables.

学生人口统计表已添加到数据库以演示此用法。 该视图将合并这些表。

Notes:

笔记:

  • To “join” tables, the tables must have fields in common (usually primary keys) that uniquely identity each row. In this case it’s the student ID. (More on this in the SQL Joins guide.)

    要“联接”表,表必须具有唯一标识每一行的公用字段(通常是主键)。 在这种情况下,这是学生证。 (有关更多信息,请参见《 SQL Joins指南》。)

  • Notice the “alias” given to each table (“s” for student and “sc” for student contact). This is a tool to shorten the table names and make it easier to identify which table is being used. It’s easier than typing long table names repeatedly. In this example, it was required because studentID is the same column name in both tables, and the system would present an “ambiguous column name error” without specifying which table to use.注意每个表的“别名”(学生用“ s”,学生联系用“ sc”)。 这是一个缩短表名并使其更容易识别正在使用的表的工具。 比重复输入长表名要容易。 在此示例中,这是必需的,因为StudentID在两个表中都是相同的列名,并且系统将显示“模棱两可的列名错误”而不指定要使用的表。

翻译自: https://www.freecodecamp.org/news/sql-create-view-mysql/

mysql创建视图sql

mysql创建视图sql_SQL视图介绍-如何在SQL和MySQL中创建视图相关推荐

  1. 如何在 GitHub 的项目中创建一个分支呢?

    https://www.cnblogs.com/plBlog/p/11573234.html https://www.cnblogs.com/wulibo/p/10608471.html https: ...

  2. SQL Server Replication 中关于视图的点滴

    原文:SQL Server Replication 中关于视图的点滴 在服务器A数据库TEST新建了一个本地发布(Local Publications)RPL_GES_MIS_TEST,在服务器B数据 ...

  3. 如何在Ubuntu 16.04中创建GIF动图

    大 家经常在新浪微薄.QQ.facebook.twitter 中看到有趣的 GIF 动图吧,GIF 文件比视频小.比静态 JPG 图片形像生动,非常适于互联网上的搞笑帖子.产品展示和功能步骤演示,所以 ...

  4. html 下拉框设置名称,html下拉菜单怎么做?高手教你如何在HTML和CSS中创建下拉菜单...

    html下拉菜单怎么做?html下拉菜单代码是什么?这些对于刚刚入门的新手,还不是很明白,下面高手教你如何在HTML和CSS中创建下拉菜单? 很多人都会遇到将鼠标悬停在导航上,会出现下拉菜单; 一般出 ...

  5. 如何在Power BI Desktop中创建词云生成器

    In this article, we'll look at how to create a Word cloud generator in Power BI Desktop, including i ...

  6. power bi 创建空表_如何使用R在Power BI中创建地理地图

    power bi 创建空表 介绍 (Introduction) This is the fifth article of a series dedicated to discovering geogr ...

  7. 如何在SQL Server数据库中加密数据

    如何在SQL Server数据库中加密数据 为了防止某些别有用心的人从外部访问数据库,盗取数据库中的用户姓名.密码.信用卡号等其他重要信息,在我们创建数据库驱动的解决方案时,我们首先需要考虑的的第一条 ...

  8. 使用SQL查询系统中创建的个性化

    使用SQL查询系统中创建的个性化 在项目实施过程中,Oracle EBS标准功能不一定能够完美满足客户的需求,可能就需要对系统界面做一些个性化.个性化可以在使用少许代码或不使用代码的条件下,实现简单的 ...

  9. C# 如何在PDF文档中创建表格

    表格能够直观的传达数据信息,使信息显得条理化,便于阅读同时也利于管理.那在PDF类型的文档中如何来添加表格并且对表格进行格式化操作呢?使用常规方法直接在PDF中添加表格行不通,那我们可以在借助第三方组 ...

最新文章

  1. java保存不了_在使用Java写入文件时,文件不能保存在文件夹中
  2. java二维整型数组 各行和排序_java:已知我有一个二维数组,直接输入全部数据,怎么对数组的每行进行升序排序...
  3. Android 常用的性能分析工具详解:GPU呈现模式, TraceView, Systrace, HirearchyViewer(转)...
  4. mysql 基础视图_MySQL基础(4) | 视图
  5. 有上下界网络流问题汇总
  6. mysql+if+x+mod+2_MySQL常用函数 二
  7. mysql5.0.x统计每秒增删改查替换数及系统每秒磁盘IO
  8. Jack Dorsey首条推文NFT的买家在伊朗被捕
  9. 一个人越来越有潜力的3个迹象
  10. 批量操作权限的页面展示
  11. react native webview 百度地图_react-native-baidu-map使用及注意问题
  12. 【百度网盘】老罗android开发视频教程[压缩后3.63G]
  13. Excel函数实战技巧精粹(六)如何在条件格式中使用函数
  14. 【MATLAB图像读取】
  15. 基于LabVIEW的计时器
  16. 一、DC DC电源转换电路设计
  17. Apache PdfBox 2.0.X 版本解析PDF文档(文字和图片)
  18. windows 10 平台安装 vim 插件 YouCompleteMe 详细流程
  19. 《美味在哪》场景绘画教程
  20. MICROS RES安装

热门文章

  1. Maven——windows下安装配置及IDEA设置本地仓库的步骤总结
  2. ktv项目小结 9206 随堂
  3. 案例 解析频道节目单 c# 1614261055
  4. java封装 1210 速记
  5. 2020-django目录
  6. dj电商-数据库的远程连接
  7. python-jieba分词模块
  8. javascript-分支与循环
  9. Linux物理CPU及逻辑CPU查看
  10. binlog2sql使用总结