Home Database Mysql Tutorial 视图与临时表

视图与临时表

Jun 07, 2016 pm 03:56 PM
Sudden view

今天上午闲来无事,突然想写写视图与临时表的作用,如下:

相关mysql视频教程推荐:《mysql教程

视图:

视图的定义:从一个或多个表(或视图)导出的表。

视图与表的不同之处:视图是一个虚表,即视图所对应的数据不进行实际存储,数据库只存储视图的定义,对视图的数据进行操作时,系统根据视图的定义去操作与视图相关联的基本表。

上面小段其实已经讲出了视图的本质特征。

视图主要用于系统的安全、查询和效率,在安全方面,举个例子:例如,你只想让用户看到某一表的某几个字段,有些字段想不让用户看见,这是用视图解决会很好,当然在select时也可以实现。第在查询方面,对于比较复杂的查询,可以大大减少频繁编写sql语句的烦恼。同时,在效率上,数据分布在多台服务器上,视图一定会带来效率上的好处。

临时表:

临时表与永久表相似,但临时表存储在 tempdb 中,当不再使用时会自动删除。
临时表有两种类型:本地和全局。它们在名称、可见性以及可用性上有区别。本地临时表的名称以单个数字符号 (#) 打头;它们仅对当前的用户连接是可见的;当用户从 SQL Server 实例断开连接时被删除。全局临时表的名称以两个数字符号 (##) 打头,创建后对任何用户都是可见的,当所有引用该表的用户从 SQL Server 断开连接时被删除。

例如,如果创建了 employees 表,则任何在数据库中有使用该表的安全权限的用户都可以使用该表,除非已将其删除。如果数据库会话创建了本地临时表 #employees,则仅会话可以使用该表,会话断开连接后就将该表删除。如果创建了 ##employees 全局临时表,则数据库中的任何用户均可使用该表。如果该表在您创建后没有其他用户使用,则当您断开连接时该表删除。如果您创建该表后另一个用户在使用该表,则 SQL Server 将在您断开连接并且所有其他会话不再使用该表时将其删除。
临时表主要用来提高效率。

二者区别:
空间分配:物理空间的分配不一样,试图不分配空间, 临时表会分配空间
虚实:视图是一条预编译的SQL语句,并不保存实际数据,而临时表是保存在tempdb中的实际的表。即视图是一个快照,是一个虚表,而临时表是客观存在的表类型对象。它们的结构一个是表、一个快照。可以把视图想象成联合表的快捷方式。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Two Point Museum: All Exhibits And Where To Find Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to implement editable tables in Vue How to implement editable tables in Vue Nov 08, 2023 pm 12:51 PM

Tables are an essential component in many web applications. Tables usually have large amounts of data, so tables require some specific features to improve user experience. One of the important features is editability. In this article, we will explore how to implement editable tables using Vue.js and provide specific code examples. Step 1: Prepare the data First, we need to prepare the data for the table. We can use a JSON object to store the table's data and store it in the data property of the Vue instance. In this case

iOS 17's standby mode turns a charging iPhone into a home hub iOS 17's standby mode turns a charging iPhone into a home hub Jun 06, 2023 am 08:20 AM

In iOS 17 Apple is introducing Standby Mode, a new display experience designed for charging iPhones in a horizontal orientation. In this position, the iPhone is able to display a series of full-screen widgets, turning it into a useful home hub. Standby mode automatically activates on an iPhone running iOS 17 placed horizontally on the charger. You can view time, weather, calendar, music controls, photos, and more. You can swipe left or right through the available standby options and then long press or swipe up/down to customize. For example, you can choose from analog view, digital view, bubble font, and daylight view, where the background color changes based on time as time passes. There are some options

Understand the differences and comparisons between SpringBoot and SpringMVC Understand the differences and comparisons between SpringBoot and SpringMVC Dec 29, 2023 am 09:20 AM

Compare SpringBoot and SpringMVC and understand their differences. With the continuous development of Java development, the Spring framework has become the first choice for many developers and enterprises. In the Spring ecosystem, SpringBoot and SpringMVC are two very important components. Although they are both based on the Spring framework, there are some differences in functions and usage. This article will focus on comparing SpringBoot and Spring

Laravel development: How to generate views using Laravel View? Laravel development: How to generate views using Laravel View? Jun 14, 2023 pm 03:28 PM

Laravel is one of the most popular PHP frameworks currently, and its powerful view generation capabilities are impressive. A view is a page or visual element displayed to the user in a web application, which contains code such as HTML, CSS, and JavaScript. LaravelView allows developers to use a structured template language to build web pages and generate corresponding views through controllers and routing. In this article, we will explore how to generate views using LaravelView. 1. What

How to use CodeIgniter4 framework in php? How to use CodeIgniter4 framework in php? May 31, 2023 pm 02:51 PM

PHP is a very popular programming language, and CodeIgniter4 is a commonly used PHP framework. When developing web applications, using frameworks is very helpful. It can speed up the development process, improve code quality, and reduce maintenance costs. This article will introduce how to use the CodeIgniter4 framework. Installing the CodeIgniter4 framework The CodeIgniter4 framework can be downloaded from the official website (https://codeigniter.com/). Down

What are the views in Word? What are the views in Word? Mar 19, 2024 pm 06:10 PM

I guess that many students want to learn the typesetting skills of Word, but the editor secretly tells you that before learning the typesetting skills, you need to understand the word views clearly. In Word2007, 5 views are provided for users to choose. These 5 views include pages. View, reading layout view, web layout view, outline view and normal view, let’s learn about these 5 word views with the editor today. 1. Page view Page view can display the appearance of the print result of the Word2007 document, which mainly includes headers, footers, graphic objects, column settings, page margins and other elements. It is the page view closest to the print result. 2. Reading layout view Reading layout view displays Word2007 documents and Office in the column style of a book

Detailed explanation of views in Django framework Detailed explanation of views in Django framework Jun 17, 2023 am 10:18 AM

Django is a highly customizable web framework that provides many convenient tools and libraries to help developers quickly create high-performance, scalable web applications. Among them, views are one of the most important components of the Django framework. Views are responsible for processing requests from clients and returning corresponding responses. In this article, we'll take a deep dive into views in the Django framework and explain how to use it to create high-performance, customizable web applications. 1. The basic concept of views in Django

Microsoft updates Visual Studio Code 1.80 Microsoft updates Visual Studio Code 1.80 Jul 10, 2023 pm 08:13 PM

Microsoft recently launched Visual Studio Code 1.80. Although this update was released in July, the official still calls it the June update. After users install this update, the built-in terminal can directly display images, and auxiliary functions have also been optimized. In the previously released preview version of Visual Studio Code, support for images in the terminal has been supported, and it is enabled by default in the new 1.80 version. In order to be able to display the image in the terminal, the image pixel data is converted into text through a special escape sequence and finally written to the terminal. If you want to pipe typical PNG, GIF or JPEG files to the terminal, you need to install the imgcatpython package and then run imgc in the terminal

See all articles