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.pswp.cn/news/376995.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/376995.shtml
英文地址,請注明出處:http://en.pswp.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 * …