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

SQL ServerÐÔÄܵĸĽøµÃÒæÓÚÂß¼­Êý¾Ý¿âÉè¼Æ (ת)

¡ô1¡¢Ê¹ÓÃË÷ÒýÀ´¸ü¿ìµØ±éÀú±í
 
ȱʡÇé¿öϽ¨Á¢µÄË÷ÒýÊÇ·ÇȺ¼¯Ë÷Òý£¬µ«ÓÐʱËü²¢²»ÊÇ×î¼ÑµÄ¡£ÔÚ·ÇȺ¼¯Ë÷ÒýÏ£¬Êý¾ÝÔÚÎïÀíÉÏËæ»ú´æ·ÅÔÚÊý¾ÝÒ³ÉÏ¡£ºÏÀíµÄË÷ÒýÉè¼ÆÒª½¨Á¢ÔÚ¶Ô¸÷ÖÖ²éѯµÄ·ÖÎöºÍÔ¤²âÉÏ¡£Ò»°ãÀ´Ëµ£º¢Ù.ÓдóÁ¿Öظ´Öµ¡¢ÇÒ¾­³£Óз¶Î§²éѯ£¨between, > ,< £¬> =,< =£©ºÍorder by¡¢group by·¢ÉúµÄÁУ¬¿É¿¼Âǽ¨Á¢Èº¼¯Ë÷Òý£»¢Ú.¾­³£Í¬Ê±´æÈ¡¶àÁУ¬ÇÒÿÁж¼º¬ÓÐÖظ´Öµ¿É¿¼Âǽ¨Á¢×éºÏË÷Òý£»¢Û.×éºÏË÷ÒýÒª¾¡Á¿Ê¹¹Ø¼ü²éѯÐγÉË÷Òý¸²¸Ç£¬ÆäÇ°µ¼ÁÐÒ»¶¨ÊÇʹÓÃ×îƵ·±µÄÁС£Ë÷ÒýËäÓÐÖúÓÚÌá¸ßÐÔÄܵ«²»ÊÇË÷ÒýÔ½¶àÔ½ºÃ£¬Ç¡ºÃÏà·´¹ý¶àµÄË÷Òý»áµ¼ÖÂϵͳµÍЧ¡£Óû§ÔÚ±íÖÐÿ¼Ó½øÒ»¸öË÷Òý£¬Î¬»¤Ë÷Òý¼¯ºÏ¾ÍÒª×öÏàÓ¦µÄ¸üй¤×÷¡£
 
¡ô2¡¢IS NULL Óë IS NOT NULL
 
²»ÄÜÓÃnull×÷Ë÷Òý£¬Èκΰüº¬nullÖµµÄÁж¼½«²»»á±»°üº¬ÔÚË÷ÒýÖС£¼´Ê¹Ë÷ÒýÓжàÁÐÕâÑùµÄÇé¿öÏ£¬Ö»ÒªÕâЩÁÐÖÐÓÐÒ»Áк¬ÓÐnull£¬¸ÃÁоͻá´ÓË÷ÒýÖÐÅųý¡£Ò²¾ÍÊÇ˵Èç¹ûijÁдæÔÚ¿ÕÖµ£¬¼´Ê¹¶Ô¸ÃÁн¨Ë÷ÒýÒ²²»»áÌá¸ßÐÔÄÜ¡£ÈκÎÔÚwhere×Ó¾äÖÐʹÓÃis null»òis not nullµÄÓï¾äÓÅ»¯Æ÷ÊDz»ÔÊÐíʹÓÃË÷ÒýµÄ¡£
 
¡ô3¡¢INºÍEXISTS
 
EXISTSÒªÔ¶±ÈINµÄЧÂʸߡ£ÀïÃæ¹Øϵµ½full table scanºÍrange scan¡£¼¸ºõ½«ËùÓеÄIN²Ù×÷·û×Ó²éѯ¸ÄдΪʹÓÃEXISTSµÄ×Ó²éѯ¡£
 
¡ô4¡¢ÔÚº£Á¿²éѯʱ¾¡Á¿ÉÙÓøñʽת»»¡£
 
¡ô5¡¢µ±ÔÚSQL SERVER 2000ÖУ¬Èç¹û´æ´¢¹ý³ÌÖ»ÓÐÒ»¸ö²ÎÊý£¬²¢ÇÒÊÇOUTPUTÀàÐ͵ģ¬±ØÐëÔÚµ÷ÓÃÕâ¸ö´æ´¢¹ý³ÌµÄʱºò¸øÕâ¸ö²ÎÊýÒ»¸ö³õʼµÄÖµ£¬·ñÔò»á³öÏÖµ÷ÓôíÎó¡£
 
¡ô6¡¢ORDER BYºÍGROPU BY
 
ʹÓÃORDER BYºÍGROUP BY¶ÌÓÈκÎÒ»ÖÖË÷Òý¶¼ÓÐÖúÓÚSELECTµÄÐÔÄÜÌá¸ß¡£×¢ÒâÈç¹ûË÷ÒýÁÐÀïÃæÓÐNULLÖµ£¬Optimizer½«ÎÞ·¨ÓÅ»¯¡£
 
¡ô7¡¢ÈκζÔÁеIJÙ×÷¶¼½«µ¼Ö±íɨÃ裬Ëü°üÀ¨Êý¾Ý¿âº¯Êý¡¢¼ÆËã±í´ïʽµÈµÈ£¬²éѯʱҪ¾¡¿ÉÄܽ«²Ù×÷ÒÆÖÁµÈºÅÓұߡ£
 
¡ô8¡¢IN¡¢OR×Ӿ䳣»áʹÓù¤×÷±í£¬Ê¹Ë÷ÒýʧЧ¡£Èç¹û²»²úÉú´óÁ¿Öظ´Öµ£¬¿ÉÒÔ¿¼ÂÇ°Ñ×Ó¾ä²ð¿ª¡£²ð¿ªµÄ×Ó¾äÖÐÓ¦¸Ã°üº¬Ë÷Òý¡£
 
¡ô9¡¢SET SHOWPLAN_ALL ON ²é¿´Ö´Ðз½°¸¡£DBCC¼ì²éÊý¾Ý¿âÊý¾ÝÍêÕûÐÔ¡£
 
DBCC(DataBase Consistency Checker£©ÊÇÒ»×éÓÃÓÚÑéÖ¤ SQL Server Êý¾Ý¿âÍêÕûÐԵijÌÐò¡£
 
¡ô10¡¢É÷ÓÃÓαê
 
ÔÚijЩ±ØÐëʹÓÃÓαêµÄ³¡ºÏ£¬¿É¿¼Âǽ«·ûºÏÌõ¼þµÄÊý¾ÝÐÐתÈëÁÙʱ±íÖУ¬ÔÙ¶ÔÁÙʱ±í¶¨ÒåÓαê½øÐвÙ×÷£¬ÕâÑù¿ÉʹÐÔÄܵõ½Ã÷ÏÔÌá¸ß¡£
 
ÓÅ»¯Êý¾Ý¿âµÄ


Ïà¹ØÎĵµ£º

SQL Server 2005 Analysis Services²¿Êðʱ±¨¸æ´íÎó

 Êý¾ÝÔ´......°üº¬ÎÞ·¨ÓÃÓÚ´¦Àí²Ù×÷µÄ ImpersonationMode¡£
½â¾ö·½·¨£º
·þÎñÆ÷Á¬½Ó¸ÄΪ“ʹÓ÷þÎñÕË»§”¡£
¾ßÌå²Ù×÷£º
ÔÚÊý¾ÝÔ´ÀïµÄÏîÄ¿Éϵã»÷ÓÒ¼ü->´ò¿ª->Êý¾ÝÔ´Éè¼ÆÆ÷ £¬ Ñ¡Ôñ“Ä£ÄâÐÅÏ¢”±êÇ©->Ñ¡Ôñ“ʹÓ÷þÎñÕË»§”£¬È·¶¨£¬Ö´Ðв¿Êð¡£ ......

ÅäÖÃSQL Server 2005 ÒÔÔÊÐíÔ¶³ÌÁ¬½Ó

SQL Server 2005 ¿ª·¢°æ²»ÔÊÐíÔ¶³ÌÁ¬½Ó¡£
¡¡¡¡ÒªÔÊÐíÔ¶³ÌÁ¬½ÓSQL Server 2005 ,ÐèÒªÍê³ÉÒÔϲ½Ö裺
•ÔÚSQLServer ʵÀýÉÏÆôÓÃÔ¶³ÌÁ¬½Ó¡£
•´ò¿ª·þÎñÆ÷ SQLBrowser ·þÎñ¡£
•ÅäÖ÷À»ðǽÒÔÔÊÐíSQLBrowser ·þÎñºÍSQLServer·þÎñÍøÂçͨÐÅ¡£
¡¡¡¡ÔÚSQLServer ʵÀýÉÏÆôÓÃÔ¶³ÌÁ¬½Ó
1.Ö¸Ïò“¿ªÊ¼->³ÌÐ ......

¾«ÃîSQLÓï¾ä

 1.°´ÐÕÊϱʻ­ÅÅÐò:
Select * from TableName Order By CustomerName Collate Chinese_PRC_Stroke_ci_as
2.·ÖÒ³SQLÓï¾ä
select * from(select (row_number() OVER (ORDER BY tab.ID Desc)) as rownum,tab.* from ±íÃû As tab) As t where rownum between ÆðʼλÖà And ½áÊøλÖÃ
3.»ñÈ¡µ±Ç°Êý¾Ý¿âÖеÄËùÓÐÓû§± ......

¶¯Ì¬SQL»ù±¾Óï·¨

1 :ÆÕͨSQLÓï¾ä¿ÉÒÔÓÃexecÖ´ÐÐ
Select * from tableName
exec('select * from tableName')
exec sp_executesql N'select * from tableName' -- Çë×¢Òâ×Ö·û´®Ç°Ò»¶¨Òª¼ÓN
2:×Ö¶ÎÃû£¬±íÃû£¬Êý¾Ý¿âÃûÖ®Àà×÷Ϊ±äÁ¿Ê±£¬±ØÐëÓö¯Ì¬SQL
declare @fname varchar(20)
set @fname = 'FiledName'
Select @fname from tab ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ