how things work : sql select statement
原网站无法访问,故保留google快照
How things work :
SQL
Select
Statement
Introduction
:
Ever asked your self how things work inside the
SQL
Select
statement? In this article we won’t be talking about how to writeSQL
Select
statement but rather we will be talking about the algorithms and the methodology behind the
Select
statement and how
SQL
decides which
algorithm
it will use to filter out the results and return our expected results.
Selecting an
Algorithm
:
In fact you can’t do so, it is up to the
SQL
Optimizer implementation to determine the selected
algorithm
that best match the query you are going to invoke in order to enhance the query performance or in other words Optimize it, so you don’t have control over selecting the
algorithm
although some
SQL
Optimizer implementations tried to enable the DB Admin to specify which selection
algorithm
is suitable based on the admin knowledge (for example the admin might know that binary search –we will mentioned that latter- might be the best choice).
The Preparation:
We need to get prepared first and get familiar with the terminologies that we will be using through the article
Before we go further we need to know the types of indexes:
• Primary index – allows records to be read in an order that corresponds to the physical order in the file.
• Secondary index – any index that is not a primary index.
When we make an index we create something like a database for Indexing except it only include the key being indexed and the location counter which holds the location on the record in the database itself (the one that contains the data).
Access path: An access path is an
algorithm
used by Database to satisfy the requirements of
SQL
statements.
相关文档:
select name from syscolumns where id in (select id from sysobjects where type = 'u' and name = '相应表名')
用以上sql语句输入相应表名就可以查到表的字段名,对应好数据库 查询是否存在该表语句
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[tb_cost]') and OBJECTPROPER ......
*
sql xml 入门:
--by jinjazz
--http://blog.csdn.net/jinjazz
1、xml: 能认识元素、属性和值
2、xpath: 寻址语言,类似wind ......
SQL Server:
Select TOP N * from TABLE Order By NewID()
Select TOP N * from TABLE Order By NewID()
NewID()函数将创建一个 uniqueidentifier 类型的唯一值。上面的语句实现效果是从Table中随机读取N条记录。
Access:
Select TOP N *&n ......
----start
动态SQL是在程序运行时构造的,要执行单条SQL,使用EXECUTE IMMEDATE 语句;当批量执行SQL时,先使用PREPARE 语句构造SQL,然后使用EXECUTE 语句执行。
一:Prepare语句:用来构造批量SQL
语法:
PREPARE <sql-statement> [OUTPUT] INTO <result> [INPUT INTO] <input> ......
最近发现我们公司的ASP.NET的代码有拼接SQL语句的习惯!这是非常危险的。以下我举例说明一下
例子1:
statement := "SELECT * from users WHERE name = '" + userName + "'; "
将用户名变量(即username)设置为:
a' or 't'='t,此时原始语句发生了变化:
SELECT * from users WHERE name = 'a' OR 't'='t';
如果这 ......