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

SQL Server²éѯËٶȻºÂý½â¾ö°ì·¨(1)

SQL ServerÊý¾Ý¿â²éѯËÙ¶ÈÂýµÄÔ­ÒòÓкܶ࣬³£¼ûµÄÓÐÒÔϼ¸ÖÖ£º
1¡¢Ã»ÓÐË÷Òý»òÕßûÓÐÓõ½Ë÷Òý(ÕâÊDzéѯÂý×î³£¼ûµÄÎÊÌ⣬ÊdzÌÐòÉè¼ÆµÄȱÏÝ)
2¡¢I/OÍÌÍÂÁ¿Ð¡£¬ÐγÉÁËÆ¿¾±Ð§Ó¦¡£
3¡¢Ã»Óд´½¨¼ÆËãÁе¼Ö²éѯ²»ÓÅ»¯¡£
4¡¢ÄÚ´æ²»×ã
5¡¢ÍøÂçËÙ¶ÈÂý
6¡¢²éѯ³öµÄÊý¾ÝÁ¿¹ý´ó(¿ÉÒÔ²ÉÓöà´Î²éѯ£¬ÆäËûµÄ·½·¨½µµÍÊý¾ÝÁ¿)
7¡¢Ëø»òÕßËÀËø(ÕâÒ²ÊDzéѯÂý×î³£¼ûµÄÎÊÌ⣬ÊdzÌÐòÉè¼ÆµÄȱÏÝ)
8¡¢sp_lock,sp_who£¬»î¶¯µÄÓû§²é¿´£¬Ô­ÒòÊǶÁд¾ºÕù×ÊÔ´¡£
9¡¢·µ»ØÁ˲»±ØÒªµÄÐкÍÁÐ
10¡¢²éѯÓï¾ä²»ºÃ£¬Ã»ÓÐÓÅ»¯
¡ñ¿ÉÒÔͨ¹ýÒÔÏ·½·¨À´ÓÅ»¯²éѯ£º
1¡¢°ÑÊý¾Ý¡¢ÈÕÖ¾¡¢Ë÷Òý·Åµ½²»Í¬µÄI/OÉ豸ÉÏ£¬Ôö¼Ó¶ÁÈ¡Ëٶȣ¬ÒÔÇ°¿ÉÒÔ½«TempdbÓ¦·ÅÔÚRAID0ÉÏ£¬SQL2000²»ÔÚÖ§³Ö¡£Êý¾ÝÁ¿(³ß´ç)Ô½´ó£¬Ìá¸ßI/OÔ½ÖØÒª¡£
2¡¢×ÝÏò¡¢ºáÏò·Ö¸î±í£¬¼õÉÙ±íµÄ³ß´ç(sp_spaceuse)
3¡¢Éý¼¶Ó²¼þ
4¡¢¸ù¾Ý²éѯÌõ¼þ£¬½¨Á¢Ë÷Òý£¬ÓÅ»¯Ë÷Òý¡¢ÓÅ»¯·ÃÎÊ·½Ê½£¬ÏÞÖƽá¹û¼¯µÄÊý¾ÝÁ¿¡£×¢ÒâÌî³äÒò×ÓÒªÊʵ±(×îºÃÊÇʹÓÃĬÈÏÖµ0)¡£Ë÷ÒýÓ¦¸Ã¾¡Á¿Ð¡£¬Ê¹ÓÃ×Ö½ÚÊýСµÄÁн¨Ë÷ÒýºÃ(²ÎÕÕË÷ÒýµÄ´´½¨)£¬²»Òª¶ÔÓÐÏ޵ļ¸¸öÖµµÄ×ֶν¨µ¥Ò»Ë÷ÒýÈçÐÔ±ð×ֶΡ£
5¡¢Ìá¸ßÍøËÙ¡£
6¡¢À©´ó·þÎñÆ÷µÄÄÚ´æ,Windows 2000ºÍSQL server 2000ÄÜÖ§³Ö4-8GµÄÄÚ´æ¡£
ÅäÖÃÐéÄâÄڴ棺ÐéÄâÄÚ´æ´óСӦ»ùÓÚ¼ÆËã»úÉϲ¢·¢ÔËÐеķþÎñ½øÐÐÅäÖá£ÔËÐÐMicrosoft SQL Server 2000ʱ£¬¿É¿¼Âǽ«ÐéÄâÄÚ´æ´óСÉèÖÃΪ¼ÆËã»úÖа²×°µÄÎïÀíÄÚ´æµÄ1.5±¶¡£Èç¹ûÁíÍâ°²×°ÁËÈ«ÎļìË÷¹¦ÄÜ£¬²¢´òËãÔËÐÐMicrosoftËÑË÷·þÎñÒÔ±ãÖ´ÐÐÈ«ÎÄË÷ÒýºÍ²éѯ£¬¿É¿¼ÂÇ£º½«ÐéÄâÄÚ´æ´óСÅäÖÃΪÖÁÉÙÊǼÆËã»úÖа²×°µÄÎïÀíÄÚ´æµÄ3±¶¡£½«SQL Server max server memory·þÎñÆ÷ÅäÖÃÑ¡ÏîÅäÖÃΪÎïÀíÄÚ´æµÄ1.5±¶(ÐéÄâÄÚ´æ´óСÉèÖõÄÒ»°ë)¡£
7¡¢Ôö¼Ó·þÎñÆ÷CPU¸öÊý£»µ«ÊDZØÐëÃ÷°×²¢Ðд¦Àí´®Ðд¦Àí¸üÐèÒª×ÊÔ´ÀýÈçÄڴ档ʹÓò¢Ðл¹ÊÇ´®ÐгÌÊÇMSSQL×Ô¶¯ÆÀ¹ÀÑ¡ÔñµÄ¡£µ¥¸öÈÎÎñ·Ö½â³É¶à¸öÈÎÎñ£¬¾Í¿ÉÒÔÔÚ´¦ÀíÆ÷ÉÏÔËÐС£ÀýÈçµ¢¸é²éѯ µÄÅÅÐò¡¢Á¬½Ó¡¢É¨ÃèºÍGROUP BY×Ö¾äͬʱִÐУ¬SQL SERVER¸ù¾ÝϵͳµÄ¸ºÔØÇé¿ö¾ö¶¨×îÓŵIJ¢Ðеȼ¶£¬¸´ÔÓµÄÐèÒªÏûºÄ´óÁ¿µÄCPUµÄ²éѯ×îÊʺϲ¢Ðд¦Àí¡£µ«ÊǸüвÙ×÷UPDATE£¬INSERT£¬DELETE»¹²»Äܲ¢Ðд¦Àí¡£
8¡¢Èç¹ûÊÇʹÓÃlike½øÐвéѯµÄ»°£¬¼òµ¥µÄʹÓÃindexÊDz»Ðеģ¬µ«ÊÇÈ«ÎÄË÷Òý£¬ºÄ¿Õ¼ä¡£like “a%”ʹÓÃË÷Òýlike “%a” ²»Ê¹ÓÃË÷ÒýÓÃlike “%a%” ²éѯʱ£¬²éѯºÄʱºÍ×Ö¶ÎÖµ×ܳ¤¶È³ÉÕý±È£¬ËùÒÔ²»ÄÜÓÃCHARÀàÐÍ£¬¶øÊÇVARCHAR¡£¶ÔÓÚ×ֶεÄÖµºÜ³¤µÄ½¨È«ÎÄË÷Ò


Ïà¹ØÎĵµ£º

SQL²éѯÓï¾äʹÓÃ

Ò»¡¢¼òµ¥²éѯ
¡¡¡¡ ¼òµ¥µÄTransact-SQL²éѯֻ°üÀ¨Ñ¡ÔñÁÐ±í¡¢from×Ó¾äºÍWHERE×Ӿ䡣
ËüÃÇ·Ö±ð˵Ã÷Ëù²éѯÁС¢²éѯµÄ
±í»òÊÓͼ¡¢ÒÔ¼°ËÑË÷Ìõ¼þµÈ¡£
ÀýÈ磬ÏÂÃæµÄÓï¾ä²éѯtesttable±íÖÐÐÕÃûΪ“ÕÅÈý”µÄnickname×ֶκÍemail×ֶΡ£
SELECT nickname,email
from testtable WHERE name='ÕÅÈý'
(Ò»)Ñ¡ÔñÁбí
¡ ......

sqlÊÂÎñ´¦Àí


 
BEGIN TRANSACTION--¿ªÊ¼ÊÂÎñ
DECLARE @errorSun INT --¶¨Òå´íÎó¼ÆÊýÆ÷
SET @errorSun=0 --û´íΪ0
UPDATE a SET id=232 WHERE a=1 --ÊÂÎñ²Ù×÷SQLÓï¾ä
SET @errorSun=@errorSun+@@ERROR --ÀÛ¼ÆÊÇ·ñÓдí
UPDATE aa SET id=2 WHERE a=1 --ÊÂÎñ²Ù×÷SQLÓï¾ä
SET @errorSun=@errorSun+@@ERROR --ÀÛ¼ÆÊÇ·ñÓдí
I ......

SQLÖг£Óú¯ÊýµÄÕûÀí

¶ÔÓÚsqlÖеĺ¯Êý¿ÉνÊǶàµÄ²»Ê¤Ã¶¾Ù£¬±¾ÎÄ´Ó³£Óú¯ÊýµÄ½Ç¶È¶ÔÆ亯Êý½øÐÐ×ܽ᣺1¡¢ÈÕÆÚºÍʱ¼äº¯Êý2¡¢×Ö·û´®º¯Êý3¡¢ÏµÍ³º¯ÊýÁ÷³Ì¿ØÖÆÓï¾ä
1¡¢  ÈÕÆÚºÍʱ¼äº¯Êý
¶ÔÓÚÈÕÆÚº¯ÊýÎÒÃÇ¿ÉÒÔ·ÖΪ2СÀà½øÐзÖÎö´¦Àí£¬
A¡¢ ÈÕÆÚµÄÕûÌå´¦Àíº¯Êý£¬¾ßÌåµÄº¬ÒåºÍÓï·¨ÈçÏÂËùʾ£º
DATEADD(datepart,number,date)
µÚÒ»¸ö²ÎÊý˵Ã÷ÒªÌí ......

С²¼×÷Æ·£ºOracle 11g SQL»ù´¡ÈëÃÅϵÁÐÅàѵ(È«30½²)

==============================================
 
µÚ01½²: Chapter 00--Oracle 11g SQL Fundamentals Training Introduction
ÔÚÏß¹Û¿´£º http://www.boobooke.com/v/bbk2003
ÊÓƵÏÂÔØ£º http://www.boobooke.com/v/bbk2003.zip
 
µÚ02½²: Chapter 00--Oracle 11g SQL Fundamentals Training Introduction ......

SQL²éѯÓï¾ä¾«»ªÊ¹ÓüòÒª

Ò»¡¢ ¼òµ¥²éѯ
¡¡¡¡¼òµ¥µÄTransact-SQL²éѯֻ°üÀ¨Ñ¡ÔñÁÐ±í¡¢from×Ó¾äºÍWHERE×Ӿ䡣ËüÃÇ·Ö±ð˵Ã÷Ëù²éѯÁС¢²éѯµÄ±í»òÊÓͼ¡¢ÒÔ¼°ËÑË÷Ìõ¼þµÈ¡£
¡¡¡¡ÀýÈ磬ÏÂÃæµÄÓï¾ä²éѯtesttable±íÖÐÐÕÃûΪ“ÕÅÈý”µÄnickname×ֶκÍemail×ֶΡ£
¡¡¡¡SELECT nickname,email
¡¡¡¡from testtable
¡¡¡¡WHERE name='ÕÅÈý'
......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ