Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

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.


Ïà¹ØÎĵµ£º

SQLʱ¼äº¯Êý


Sqlʱ¼äº¯Êý
Ò»¡¢sql serverÈÕÆÚʱ¼äº¯Êý
Sql ServerÖеÄÈÕÆÚÓëʱ¼äº¯Êý 
1.  µ±Ç°ÏµÍ³ÈÕÆÚ¡¢Ê±¼ä 
    select getdate()  
2. dateadd  ÔÚÏòÖ¸¶¨ÈÕÆÚ¼ÓÉÏÒ»¶Îʱ¼äµÄ»ù´¡ÉÏ£¬·µ»ØеĠdatetime Öµ
    ......

SQL¼¶Áª¸üкͼ¶ÁªÉ¾³ý

alter table ±íÃû
add constraint Ô¼ÊøÃû
foreign key(×Ö¶ÎÃû) references Ö÷±íÃû(×Ö¶ÎÃû)
on delete cascade
Óï·¨£º
Foreign Key
(column[,...n])
references referenced_table_name[(ref_column[,...n])]
[on delete cascade]
[on update cascade]
×¢ÊÍ£º
column:ÁÐÃû
referenced_table_name:Íâ¼ü²Î¿¼µÄÖ÷¼ü± ......

SQL²éѯÓï¾ä£¨¹ØÓÚÖظ´Êý¾ÝµÄ£©

1¡¢²éѯ±íÖÐÖظ´Êý¾Ý¡£select * from people
where peopleId in (select  peopleId  from  people  group  by  peopleId  having  count(peopleId) > 1)
2¡¢É¾³ý±íÖжàÓàµÄÖظ´¼Ç¼£¬Öظ´¼Ç¼ÊǸù¾Ýµ ......

SQLÖÐÈçºÎÓÃÒ»¸ö±í¸üÐÂÁíÒ»¸ö±í

for ACCESS :
update a, b set a.name=b.name1 where a.id=b.id
for SQL Server:
"update a set a.name=b.name1 from a,b where a.id=b.id"
update   a   set   a.status=b.status  
  from   table1   a,table2   b  
&nbs ......

SQL Server2000 ÎÞ·¨´ò¿ªÆóÒµ¹ÜÀíÆ÷½â¾ö°ì·¨

½ñÌìºöÈ»ms sql2000µÄÆóÒµ¹ÜÀíÆ÷³ö´í£¬ËÑË÷ÁËÒ»ÏÂÕÒµ½Á˽â¾ö°ì·¨£¬¼Ç¼һÏ£¬·½±ãÈÕºó²éѯ
´íÎóÐÅÏ¢£º
---------------------------
Microsoft Management Console
---------------------------
MMC ²»ÄÜ´ò¿ªÎļþ C:\Program Files\Microsoft SQL Server\80\Tools\BINN\SQL Server Enterprise Manager.MSC¡£
Õâ¿ÉÄÜÊÇ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ