sql 视图嵌套视图_SQL视图

sql 视图嵌套视图

SQL | 观看次数 (SQL | Views)

Views in SQL are virtual tables. A view also has rows and columns as they're during a real table within the database. We will create a view by selecting fields from one or more tables present within the database. A View can either have all the rows of a table or specific rows supported under certain conditions. A view is nothing quite a SQL statement that's stored within the database with an associated name. A view is a composition of a table within the sort of a predefined SQL query. All rows of a table or select rows from a table can be contained inside the view. A view is often created from one or many tables which depend on the written SQL query to make a view.

SQL中的视图是虚拟表视图还具有行和列,就像它们在数据库中的真实表中一样。 我们将通过从数据库中存在的一个或多个表中选择字段来创建视图。 视图可以具有表的所有行或在特定条件下受支持的特定行。 视图只不过是存储在数据库中且具有关联名称SQL语句。 视图是预定义SQL查询中的表的组成。 表的所​​有行或表中的选择行都可以包含在视图内部。 通常从一个或多个表创建视图,这些表取决于编写SQL查询来创建视图。

Views, which are a kind of virtual tables allow users to try to the subsequent:

视图是一种虚拟表,允许用户尝试以下操作:

  1. Structure data during a way that users or classes of users find natural or intuitive.

    在用户或用户类别觉得自然或直观的方式下构造数据。

  2. Restrict access to the info in such a way that a user can see and (sometimes) modify exactly what they have and no more.

    限制访问信息的方式,使用户可以看到和(有时)准确地修改自己拥有的内容,而不再修改。

  3. Summarize data from various tables which may be wont to generate reports.

    汇总来自各种表的数据,这些数据可能不会生成报告。

Here we will discuss creating, deleting and updating views.

在这里,我们将讨论创建,删除和更新视图。

创建视图 (Creating the view)

Views can be created in SQL by using the CREATE VIEW command. This order gives the name to the view and determines the rundown of credits and tuples to be incorporated utilizing a subquery.

可以使用CREATE VIEW命令在SQL中创建视图 。 该顺序为视图指定名称,并使用子查询确定要合并的学分和元组的精简。

The syntax to create a view is given here,

这里给出了创建视图的语法,

CREATE VIEW <view_name>
As <subquery>;

For example, the command to create a view containing details of books which belong to text-book and Language Book can be specified as:

例如,用于创建包含教科书和语言书的书的详细信息的视图的命令可以指定为:

CREATE VIEW Book_1
As SELECT *
FROM BOOK
WHERE Category IN ('Textbook','LanguageBook');

Output

输出量

SQL | View Example 1

This command creates the view, named Book_1, having details of books satisfying the condition specified in the WHERE clause. The view created like this consists of all the attributes of Book relation also.

此命令创建名为Book_1的视图,该视图具有满足WHERE子句中指定条件的书籍的详细信息。 这样创建的视图也包含Book关系的所有属性。

For example, consider the command given below:

例如,考虑以下命令:

CREATE VIEW Book_2(B_code,B_title,B_category,B_price)
As SELECT ISBN,Book_Tiltle,Category,Price
FROM Book
WHERE Category IN ('Textbook','LanguageBook');

Output

输出量

SQL | View Example 2

This command creates a view Book_2, which consists of the attributes, ispn, book-name, categori, and price from the relation Book with new names, namely, b_code, b_title, b_category, and b_price respectively. Now queries can be performed on these views as they are performed on other relations.

此命令创建一个视图Book_2 ,该视图由关系Book中的属性ispn , book-name , categori和price组成,具有新名称,分别为b_code , b_title , b_category和b_price 。 现在,可以在这些视图上执行查询,就像在其他关系上执行查询一样。

Consider the example given below:

考虑下面给出的示例:

SELECT *
FROM Book_1;

Output

输出量

SQL | View Example 3
SELECT *
FROM Book_2
WHERE price>300;

Output

输出量

SQL | View Example 4
SELECT b_title, b_category
FROM Book_2
WHERE price BETWEEN 200 and 350;

Output

输出量

SQL | View Example 5

Views can contain more than one relation. The views that depend on more than one relation are known as complex views. These types of views are inefficient as they are time-consuming to execute, especially if multiple queries are involved in the view definition. Since their content is not physically stored, they are executed whenever their reference is done inside the program.

视图可以包含多个关系。 依赖于多个关系的视图称为复杂视图 。 这些类型的视图效率低下,因为它们执行起来很耗时,尤其是在视图定义中涉及多个查询的情况下。 由于它们的内容不是物理存储的,因此只要在程序内部完成引用就可以执行它们。

更新视图 (Updating Views)

A view can be updated based upon several conditions as mentioned below,

可以根据以下几种条件来更新视图,

  • Keyword DISTINCT should not be present in the SELECT statement.

    关键字DISTINCT不应出现在SELECT语句中。

  • The summary function should not be there in the SELECT statement.

    摘要函数不应在SELECT语句中存在。

  • Set function and Set Operations should not be present in the SELECT statement.

    设置函数和设置操作不应出现在SELECT语句中。

  • ORDER BY clause should not be present in the SELECT statement.

    SELECT语句中不应存在ORDER BY子句。

  • Multiple tables should not be contained in the FROM statement.

    FROM语句中不应包含多个表。

  • Subqueries should not be present inside the WHERE clause.

    子查询不应出现在WHERE子句中。

  • A query written in SQL must not contain GROUP BY or HAVING.

    用SQL编写的查询不得包含GROUP BYHAVING

  • Columns that are calculated may not get updated.

    计算的列可能不会更新。

If the view satisfies the above-mentioned conditions then the user or programmer is able to update the view. The code written below can be used for serving the purpose.

如果该视图满足上述条件,则用户或程序员可以更新该视图。 下面编写的代码可用于实现此目的。

UPDATE <Name of VIEW>
SET <parameter to be updated>=<value>
WHERE <condition>;

放下视图 (Dropping View)

The view needs to be dropped (i.e. Deleted permanently) when not in further use. The syntax for doing so is,

不使用该视图时,需要将其删除(即永久删除)。 这样做的语法是

DROP VIEW <view_name>;

翻译自: https://www.includehelp.com/sql/views.aspx

sql 视图嵌套视图

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/376995.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Postgresql多线程hashjoin(inner join)

pg hashjoin 节点大致步骤&#xff1a; 1、分块与分桶。对一个表hash时&#xff0c;确定块数和桶数量。&#xff08;一块被划分为10个元组的桶&#xff09;确定分块号与分桶号是由hashvalue决定的。 2、执行&#xff1a; 1、顺序获取S表中所有元组&#xff0c;对每一条元组Has…

iframe实现局部刷新和回调--开篇

今天做项目遇到一个问题。就是提交表单的时候&#xff0c;验证用户名是否存在和验证码是否正确。 当验证码或者用户名存在的时候。在后台弹窗提示。可页面原本file里面符合要求的值刷新没了。用户体验不好。因为用ifream刷新技术已不是什么新鲜技术。所以网上有大把的资料可参考…

Java文件类boolean setExecutable(boolean exec_file,boolean owner_access)方法,带示例

文件类boolean setExecutable(boolean exec_file&#xff0c;boolean owner_access) (File Class boolean setExecutable(boolean exec_file , boolean owner_access)) This method is available in package java.io.File.setExecutable(boolean exec_file , boolean owner_acc…

OLTP 系统和 OLAP 系统的核心设计思想

关于 OLTP 系统和 OLAP 系统的核心设计思想 数据存储系统的关于查询的典型操作&#xff1a; -- 第一种需求&#xff1a; 根据 key&#xff08;1&#xff09; 找 value&#xff08;name,age&#xff09;&#xff0c; 单点查询 select name, age from student where id 1; stu…

虚拟机

vt-x 虚拟技术的硬盘支持。想像成“硬解码”的东东。不是装虚拟机必须的&#xff0c;但有它效果会好些。 vt-x检测工具&#xff1a;securable.exe 下载地址&#xff1a;http://pan.baidu.com/s/1kTBOvzD Hardware Virtualization选项&#xff1a; no [CPU和BIOS都不支持VT] loc…

算法(转)

欢迎自荐和推荐链接。 算法 优秀博客推荐&#xff1a;各种数据结构与算法知识入门经典&#xff08;不断更新)基本算法 贪心算法&#xff1a;贪心算法 作者&#xff1a;独酌逸醉 贪心算法精讲 作者&#xff1a;3522021224 递归和分治&#xff1a;递归与分治策略 …

sjf调度算法_如何通过静态方法预测SJF调度中未来过程的突发时间?

sjf调度算法In SJF Scheduling, CPU is assigned to the process having the smallest burst time but it can not be implemented practically, because we dont know burst time of the arrived processes in advance. 在SJF Scheduling中 &#xff0c;将CPU分配给具有最短突…

flask 知识点总结

request对象的常用属性具体使用方法如下:request.headers, request.headers.get(If-None-Match)request.json, request.json[value] 或 request.json.get(detail_msg, "")request.args, request.args.get(limit, 10)来获取query parametersrequest.form, request.for…

Postgresql中的hybrid hash join(无状态机讲解)

hybrid hash join hybrid hash join是基于grace hash join 的优化。 在postgresql中的grace hash join 是这样做的&#xff1a;inner table太大不能一次性全部放到内存中&#xff0c;pg会把inner table 和outer table按照join的key分成多个分区&#xff0c;每个分区(有一个inn…

末日中的黎明

哈哈&#xff0c; 今天是2012-12-21&#xff0c;传说中的世界末日&#xff0c;不过现在看来&#xff0c;一切都是空的。。。 在这个容易记忆的日子里&#xff0c;我的博客开通了。他将伴随我以后的学习开发&#xff0c;期望我能充分利用博客&#xff0c;帮我养成常总结、常记笔…

使用numpy.tanh()打印矢量/矩阵元素的双曲正切值 使用Python的线性代数

Prerequisite: 先决条件&#xff1a; Defining a Vector 定义向量 Defining a Matrix 定义矩阵 Numpy is the library of function that helps to construct or manipulate matrices and vectors. The function numpy.tanh(x) is a function used for generating a matrix / v…

Mahout kmeans聚类

Mahout K-means聚类 一、Kmeans 聚类原理 K-means算法是最为经典的基于划分的聚类方法&#xff0c;是十大经典数据挖掘算法之一。K-means算法的基本思想是&#xff1a;以空间中k个点为中心进行聚类&#xff0c;对最靠近他们的对象归类。通过迭代的方法&#xff0c;逐次更新各聚…

Web项目中获取SpringBean——在非Spring组件中获取SpringBean

最近在做项目的时候我发现一个问题&#xff1a;Spring的IOC容器不能在Web中被引用(或者说不能被任意地引用)。我们在配置文件中让Spring自动装配&#xff0c;但并没有留住ApplicationContext的实例。我们如果希望在我们的项目中任何位置都能拿到同一个ApplicationContext来获取…

postgresql对于HashJoin算法的Data skew优化与MCV处理

Data skew 很好理解&#xff0c;即数据倾斜。现实中的数据很多都不是正态分布的&#xff0c;譬如城市人口&#xff0c;东部沿海一个市的人口与西部地区一个市地区的人口相比&#xff0c;东部城市人口会多好几倍。 postgresql的skew的优化核心思想是"避免磁盘IO"。 优…

JavaScript | 创建对象并通过JavaScript函数在表中显示其内容

In this example, we created an object named employee with id, name, gender, city, and salary and assigned and displaying the values in the table using JavaScript function. 在此示例中&#xff0c;我们创建了一个名为employee的对象&#xff0c;其对象为id &#x…

基于socket的简单文件传输系统

【实验目的及要求】 在 Uinx/Linux/Windows 环境下通过 socket 方式实现一个基于 Client/Server 文件传输程序。 【实验原理和步骤】 1. 确定传输模式:通过 socket 方式实现一个基于 Client/Server 或 P2P 模式的文件传输程序。 2. 如果选择的是 Client/Server 模式的文件传输…

《GPU高性能编程-CUDA实战》中例子头文件使用

《GPU高性能编程-CUDA实战&#xff08;CUDA By Example&#xff09;》中例子中使用的一些头文件是CUDA中和C中本身没有的&#xff0c;需要先下载这本书的源码&#xff0c;可以在&#xff1a;https://developer.nvidia.com/content/cuda-example-introduction-general-purpose-g…

mcq 队列_人工智能| AI解决问题| 才能问题解答(MCQ)| 套装1

mcq 队列1) Which of the following definitions correctly defines the State-space in an AI system? A state space can be defined as the collection of all the problem statesA state space is a state which exists in environment which is in outer spaceA state sp…

Postgresql的HashJoin状态机流程图整理

状态机 可以放大观看。 HashJoinState Hash Join运行期状态结构体 typedef struct HashJoinState {JoinState js; /* 基类;its first field is NodeTag */ExprState *hashclauses;//hash连接条件List *hj_OuterHashKeys; /* 外表条件链表;list of …

Ajax和Jsonp实践

之前一直使用jQuery的ajax方法&#xff0c;导致自己对浏览器原生的XMLHttpRequest对象不是很熟悉&#xff0c;于是决定自己写下&#xff0c;以下是个人写的deom&#xff0c;发表一下&#xff0c;聊表纪念。 Ajax 和 jsonp 的javascript 实现&#xff1a; /*! * ajax.js * …