Home Database Mysql Tutorial SQLServer 2008 技术内幕T

SQLServer 2008 技术内幕T

Jun 07, 2016 pm 03:51 PM
sql sqlserver technology programming

1、SQL编程有许多独特之处,如:面向集合的思维方式、查询元素的逻辑处理顺序、三逻辑。如果不掌握这些知识就开始用SQL编程,得到的将是冗余的、性能低下的代码,而且难以维护。 2、在SQLServer中负责生成实际工作计划(执行计划)的组件是:查询优化器(que

1、SQL编程有许多独特之处,如:面向集合的思维方式、查询元素的逻辑处理顺序、三值逻辑。如果不掌握这些知识就开始用SQL编程,得到的将是冗余的、性能低下的代码,而且难以维护。

2、在SQLServer中负责生成实际工作计划(执行计划)的组件是:查询优化器(query optimizer)。只有在确保结果集正确的前提下,优化器才会走捷径。明确区分查询的逻辑处理和物理处理是非常重要的。

3、逻辑查询的各个阶段:

(5) SELECT (5-2) DISTINCT (5-3) TOP (<top_specification>) (5-1) <select_list>
(1) FROM (1-J) <left_table> <join_type> JOIN <right_table> ON <on_predicate>
     |(1-A) <left_table> <apply_type> APPLY <right_table_expression> AS <alias>
     |(1-P) <left_table> PIVOT (<pivot_specification>) AS <alias>
     |(1-U) <left_table> UNPIVOT (<unpivot_specification>) AS <alias>
(2) WHERE <where_predicate>
(3) GROUP BY <group_by_specification>
(4) HAVING <having_predicate>
(6) ORDER BY <order_by_list>;
</order_by_list></having_predicate></group_by_specification></where_predicate></alias></unpivot_specification></left_table></alias></pivot_specification></left_table></alias></right_table_expression></apply_type></left_table></on_predicate></right_table></join_type></left_table></select_list></top_specification>
Copy after login


第一步:FROM :表示出查询的来源表,在联结运算中涉及的阶段是(1-J1)笛卡儿积、(1-J2)ON筛选器和(1-J3)添加外部行。并生成虚拟表VT1。

1.1、笛卡儿积:两表执行笛卡儿积,生成虚拟表VT1-J1。

1.2、ON筛选器:针对VT1-J1中满足ON为true的行,插入VT1-J2。

1.3、添加外部行:如果指定了OUTER JOIN (相对于CROSS JOIN或INNER JOIN ),则将保留表中没有匹配的行,作为外部行添加,生成VT1-J3。

第二步:WHERE:根据WHERE 子句中的谓词对VT1中的数据进行行筛选,只对结果为TRUE的行,插入VT2。

第三步:GROUP BY :根据group by中的列表,将VT2进行分组,每一组只有一个结果行,生成VT3。

第四步:HAVING:根据HAVING出现的谓词对VT3金信筛选,只让结果为TRUE的组才插入VT4。

第五步:SELECT:处理SELECT 子句中的元素,产生VT5。

5.1、计算表达式:根据SELECT 列表中的表达式,生成VT5-1。

5.2、DISTINCT:删除VT5-1中重复的行,生成VT5-2。

5.3、TOP:根据ORDER BY 子句定义逻辑排序,从VT5-2中选择前面指定数量或百分比的行,生产VT5-3。

第六步:ORDER BY :根据ORDER BY 子句中指定的列名,对VT5-3进行排序。生成游标VC6。

对于三值逻辑:

a、所有的查询筛选器(ON、WHERE 和HAVING )都把null当作FALSE来处理。

b、check约束中的null值被当作TRUE来对待。

c、UNIQUE约束、集合运算(UNION 和EXCEPT)、及排序和分组操作,认为两个null是相等的。

注意:

1、如果FROM 子句中有多个表运算符,则按从左到右的顺序进行处理。每个表运算符的结果作为下一个表运算符的左输入,最后生成虚拟表作为下一阶段的输入。

2、因为在WHERE之前还没对数据分组,所以WHERE 子句不能使用聚合。在筛选器中,ON对保留表中部分行的删除并不是最终的,而WHERE是最终的。只有使用外联结的时候,ON和WHERE才有逻辑区别。

3、如果在查询中指定了GROUP BY ,后续所有步骤都只能在指定的分组上操作。

4、HAVING是唯一可用于分组数据的筛选器。

5、由于SQL具有多个运算同时计算(all-at-once operation),所以SELECT 语句中的逻辑顺序是无关的。

6、ORDER BY 是唯一可以使用SELECT 中别名的步骤。







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 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
2 weeks 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)

Remove duplicate values ​​from PHP array using regular expressions Remove duplicate values ​​from PHP array using regular expressions Apr 26, 2024 pm 04:33 PM

How to remove duplicate values ​​from PHP array using regular expressions: Use regular expression /(.*)(.+)/i to match and replace duplicates. Iterate through the array elements and check for matches using preg_match. If it matches, skip the value; otherwise, add it to a new array with no duplicate values.

Where is the navicat database file? Where is the navicat database file? Apr 23, 2024 am 10:57 AM

The location where the Navicat database configuration files are stored varies by operating system: Windows: The user-specific path is %APPDATA%\PremiumSoft\Navicat\macOS: The user-specific path is ~/Library/Application Support/Navicat\Linux: The user-specific path is ~/ .config/navicat\The configuration file name contains the connection type, such as navicat_mysql.ini. These configuration files store database connection information, query history, and SSH settings.

More than just 3D Gaussian! Latest overview of state-of-the-art 3D reconstruction techniques More than just 3D Gaussian! Latest overview of state-of-the-art 3D reconstruction techniques Jun 02, 2024 pm 06:57 PM

Written above & The author’s personal understanding is that image-based 3D reconstruction is a challenging task that involves inferring the 3D shape of an object or scene from a set of input images. Learning-based methods have attracted attention for their ability to directly estimate 3D shapes. This review paper focuses on state-of-the-art 3D reconstruction techniques, including generating novel, unseen views. An overview of recent developments in Gaussian splash methods is provided, including input types, model structures, output representations, and training strategies. Unresolved challenges and future directions are also discussed. Given the rapid progress in this field and the numerous opportunities to enhance 3D reconstruction methods, a thorough examination of the algorithm seems crucial. Therefore, this study provides a comprehensive overview of recent advances in Gaussian scattering. (Swipe your thumb up

Revolutionary GPT-4o: Reshaping the human-computer interaction experience Revolutionary GPT-4o: Reshaping the human-computer interaction experience Jun 07, 2024 pm 09:02 PM

The GPT-4o model released by OpenAI is undoubtedly a huge breakthrough, especially in its ability to process multiple input media (text, audio, images) and generate corresponding output. This ability makes human-computer interaction more natural and intuitive, greatly improving the practicality and usability of AI. Several key highlights of GPT-4o include: high scalability, multimedia input and output, further improvements in natural language understanding capabilities, etc. 1. Cross-media input/output: GPT-4o+ can accept any combination of text, audio, and images as input and directly generate output from these media. This breaks the limitation of traditional AI models that only process a single input type, making human-computer interaction more flexible and diverse. This innovation helps power smart assistants

What is programming for and what is the use of learning it? What is programming for and what is the use of learning it? Apr 28, 2024 pm 01:34 PM

1. Programming can be used to develop various software and applications, including websites, mobile applications, games, and data analysis tools. Its application fields are very wide, covering almost all industries, including scientific research, health care, finance, education, entertainment, etc. 2. Learning programming can help us improve our problem-solving skills and logical thinking skills. During programming, we need to analyze and understand problems, find solutions, and translate them into code. This way of thinking can cultivate our analytical and abstract abilities and improve our ability to solve practical problems.

How to write navicat database connection url How to write navicat database connection url Apr 24, 2024 am 02:33 AM

The format of the Navicat connection URL is: protocol://username:password@host:port/database name? Parameters, which contain the information required for the connection, including protocol, username, password, hostname, port, database name and optional parameter.

The Key to Coding: Unlocking the Power of Python for Beginners The Key to Coding: Unlocking the Power of Python for Beginners Oct 11, 2024 pm 12:17 PM

Python is an ideal programming introduction language for beginners through its ease of learning and powerful features. Its basics include: Variables: used to store data (numbers, strings, lists, etc.). Data type: Defines the type of data in the variable (integer, floating point, etc.). Operators: used for mathematical operations and comparisons. Control flow: Control the flow of code execution (conditional statements, loops).

Problem-Solving with Python: Unlock Powerful Solutions as a Beginner Coder Problem-Solving with Python: Unlock Powerful Solutions as a Beginner Coder Oct 11, 2024 pm 08:58 PM

Pythonempowersbeginnersinproblem-solving.Itsuser-friendlysyntax,extensivelibrary,andfeaturessuchasvariables,conditionalstatements,andloopsenableefficientcodedevelopment.Frommanagingdatatocontrollingprogramflowandperformingrepetitivetasks,Pythonprovid

See all articles