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

SQL ServerÖÐË÷Òý

Ò»¡¢SQL ServerÖÐÊý¾ÝÐеĴ洢·½Ê½
     ÔÚSQL ServerÖдæ·ÅÊý¾ÝµÄÎļþ»áÒÔ8KBµÄ´óС·ÖÒ³¡£Ã¿Ò»Ò³¿ÉÒÔÊÇÊý¾Ý¡¢Ë÷ÒýÒÔ¼°ÆäËûSQL ServerÊý¾Ý¿âÐèҪΪÆäά»¤Êý¾ÝÎļþµÄÊý¾ÝÀàÐÍ¡£´ó¶àÊýÒ³ÊÇÊý¾ÝÒ³»òË÷ÒýÒ³¡£Ò³ÊÇSQL Server¶Á¡¢Ð´Êý¾ÝÎļþµÄµ¥Ôª¡£Ã¿Ò»Ò³Ö»°üÀ¨Ò»¸ö¶ÔÏóµÄÊý¾Ý»òË÷ÒýÐÅÏ¢£¬ËùÒÔÔÚÿһ¸öÊý¾ÝÒ³ÉÏÖ»ÄÜÕÒµ½Ò»¸ö¶ÔÏóµÄÊý¾Ý£¬Í¬ÑùÔÚÿһ¸öË÷ÒýÒ³ÉÏÒ³Ö»ÄÜÕÒµ½Ò»¸öË÷ÒýµÄÐÅÏ¢¡£
     ÔÚSQL Server2000ÖУ¬½«Ò»¸öÊý¾ÝÐд洢ÔÚ¶à¸öÒ³ÉÏÊDz»¿ÉÄܵģ¬ÕâÒâζ×ÅÒ»¸öÊý¾ÝÐбØÐëÔÚÒ»Ò³ÉÏ£¬Õâ»áµ¼ÖÂÒ»¸öÊý¾ÝÐÐÓÐ8KB´óСµÄÏÞÖÆ£¨´óÐÍÊý¾Ý¶ÔÏó³ýÍ⣩¡£
     ÔÚSQL Server2005 ÖУ¬¶ÔÓڱ䳤Êý¾ÝÀàÐÍ£¬ÀýÈçnvarchar¡¢varbinary£¬CLRµÈ£¬Êý¾ÝÐÐ8KBµÄ´óСÏÞÖƾͲ»´æÔÚÁË£¬ËùÒԱ䳤Êý¾ÝÀàÐ͵ÄÊý¾ÝÐпÉÒÔ¿çÔ½¶àÒ³¡£µ«ÊǶÔÓÚ¶¨³¤Êý¾ÝÀàÐÍ£¬Êý¾ÝÐÐÈÎÈ»±ØÐëÔÚÒ»Ò³ÉÏ¡£
 
¶þ¡¢ÈÏʶSQL ServerÖеÄË÷Òý
     Ë÷Òý·ÖΪ¾Û¼¯Ë÷ÒýºÍ·Ç¾Û¼¯Ë÷Òý¡£
     ¾Û¼¯Ë÷Òý£¨Clustered Index£©
Ø  ¾Û¼¯Ë÷ÒýµÄÒ¶½Úµã¾ÍÊÇʵ¼ÊµÄÊý¾ÝÒ³¡£
Ø  ÔÚÊý¾ÝÒ³ÖÐÊý¾Ý°´ÕÕË÷Òý˳Ðò´æ´¢¡£
Ø  ÐеÄÎïÀíλÖúÍÐÐÔÚË÷ÒýÖеÄλÖÃÊÇÏàͬµÄ¡£
Ø  ÿ¸ö±íÖ»ÄÜÓÐÒ»¸ö¾Û¼¯Ë÷Òý¡£
Ø  ¾Û¼¯Ë÷ÒýµÄƽ¾ù´óСΪ±í´óСµÄ5%¡£
Ò»¸ö¾Û¼¯Ë÷Òý¾ö¶¨ÁËÒ»¸ö±íÖÐÊý¾ÝµÄÎïÀí´æ´¢Ë³Ðò¡£Ò»¸ö¾Û¼¯Ë÷ÒýÓëÒ»¸öµç»°Ä¿Â¼ÏàËÆ£¬µç»°Ä¿Â¼ÊÇ°´ÕÕlast nameÀ´´æ·Å¡£ÒòΪ¾Û¼¯Ë÷Òý¾ö¶¨Ò»ÕűíÖÐÊý¾ÝµÄÎïÀí´æ·Å˳Ðò£¬ËùÒÔÒ»ÕűíÖ»ÄÜÓиö¾Û¼¯Ë÷Òý,Ò»¸ö¾Û¼¯Ë÷Òý¿ÉÒÔ°üº¬¶à¸öÁУ¨¸´ºÏË÷Òý£©£¬¾ÍÏñµç»°Ä¿Â¼Ò»Ñù°´ÕÕlast name ºÍ first name¼Ç¼һÑù£¬¾Û¼¯Ë÷ÒýÓëOracleÖеÄIOT'S(Index-Organized Tables)ÏàËÆ¡£
 
Ò»¸ö¾Û¼¯Ë÷Òý¶Ô·¶Î§²éѯ·Ç³£ÓÐЧÂÊefficient on columns that are often searched for ranges of values¡£µ±Óþۼ¯Ë÷Òý°ÑµÚÒ»¸öÐмìË÷³öÀ´Ö®ºó£¬ºóÐøÐÐÒ»¶¨Äܱ£Ö¤ÔÚÎïÀíÉÏÊÇÏàÁڵġ£ÀýÈ磬ӦÓõÄij¸ö²éѯÐèҪƵ·±Ö´ÐÐÒ»¸ö·¶Î§²éѯ£¬¾Û¼¯Ë÷Òý¿ÉÒÔ¿ìËÙ¶¨Î»µ½Âú×ãÌõ¼þµÄµÚÒ»¸öÊý¾Ý£¬È»ºóÔÙ¼ìË÷±íÖÐÓëÖ®ÏàÁڵļǼֱµ½×îºóÒ»Ìõ¼Ç¼¡£ÕâÑù¿ÉÒÔµ÷¸ßÕâÀà²éѯµÄÐÔÄÜ¡£ÁíÍ⣬Èç¹ûijÁо­³£ÓÃÀ´¶Ô±íÖеÄÊý¾Ý½øÐÐÅÅÐò£¨sort£©£¬¸ÃÇé¿öÏÂÒ²¿ÉÀûÓþۼ¯Ë÷ÒýÀ´½Úʡÿ´ÎÅÅÐòµÄʱ¼ä¡£
     µ±Ë÷ÒýֵΨһʱ£¬ÐèÒª²éÕÒÒ»¸öÖ¸¶¨ÐУ¬´Ëʱ¾Û¼¯Ë÷


Ïà¹ØÎĵµ£º

SQL decimal½éÉÜ

¾ßÓй̶¨ÓÐЧλÊýºÍСÊýλÊýµÄÊýÖµ×ÊÁÏÀàÐÍ¡£
decimal[ (p[ , s] )] and numeric[ (p[ , s] )]
¹Ì¶¨ÓÐЧλÊýºÍСÊýλÊýµÄÊý×Ö¡£µ±Ê¹ÓÃ×î´óÓÐЧλÊýʱ£¬ÓÐЧֵÊÇ´Ó - 10^38 +1 µ½ 10^38 - 1¡£decimal µÄ SQL-92 ͬÒå×ÖÊÇ dec ºÍ dec(p, s)¡£numeric µÄ¹¦ÄÜÏàµ±ì¶ decimal¡£
p (ÓÐЧλÊý)
¿É´¢´æµÄ×î´óÊ®½øλÊý×ÜÊý£¬Ð¡ ......

SQLÖеÄCASEʹÓ÷½·¨

Case¾ßÓÐÁ½ÖÖ¸ñʽ¡£¼òµ¥Caseº¯ÊýºÍCaseËÑË÷º¯Êý¡£
--¼òµ¥Caseº¯Êý
CASE sex
         WHEN '1' THEN 'ÄÐ'
         WHEN '2' THEN 'Å®'
ELSE 'ÆäËû' END
--CaseËÑË÷º¯Êý
CASE WHEN sex = '1' THEN 'ÄÐ'
     ......

SQL With cube

ÏÐÀ´Ð´ÏÂwith cubeµÄÓ÷¨
cubeÔËËã·ûÔÚ SELECT Óï¾äµÄ GROUP BY ×Ó¾äÖÐÖ¸¶¨¡£¸ÃÓï¾äµÄÑ¡ÔñÁбíÓ¦°üº¬Î¬¶ÈÁк;ۺϺ¯Êý±í´ïʽ¡£GROUP BY Ó¦Ö¸¶¨Î¬¶ÈÁк͹ؼü×Ö WITH CUBE¡£½á¹û¼¯½«°üº¬Î¬¶ÈÁÐÖи÷ÖµµÄËùÓпÉÄÜ×éºÏ£¬ÒÔ¼°ÓëÕâЩά¶ÈÖµ×éºÏÏàÆ¥ÅäµÄ»ù´¡ÐÐÖеľۺÏÖµ¡£
ÏÈ¿´ÏÂ±í£º
ÎÒÃÇÒÔid¾ÛºÏ²éѯ³öƽ¾ù·Ö
ÕâÒ»ÌõSQLÓï¾äÓ ......

sqlÁÐÏà¼ÓºÏ²¢ ÐÄÓêÖ®¼Ò

--1. ´´½¨±í£¬Ìí¼Ó²âÊÔÊý¾Ý
CREATE TABLE tb(id int, [value] varchar(10))
INSERT tb SELECT 1, 'aa'
UNION ALL SELECT 1, 'bb'
UNION ALL SELECT 2, 'aaa'
UNION ALL SELECT 2, 'bbb'
UNION ALL SELECT 2, 'ccc'
--SELECT * from tb
/**//*
id value
----------- ----------
1 aa
1 ......

²éѯÖظ´¼Ç¼µÄSQLÓï¾ä

SELECT tagid, tagname from uchome_mtag WHERE tagname IN (SELECT tagname from uchome_mtag GROUP BY tagname HAVING (COUNT(tagname) > 1)) ORDER BY tagname ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ