Êý¾Ý¿âË÷ÒýµÄ¸ÅÄî
Ò»¡¢Ë÷ÒýµÄ¸ÅÄî Ë÷Òý¾ÍÊǼӿì¼ìË÷±íÖÐÊý¾ÝµÄ·½·¨¡£Êý¾Ý¿âµÄË÷ÒýÀàËÆÓÚÊé¼®µÄË÷Òý¡£ÔÚÊé¼®ÖУ¬Ë÷ÒýÔÊÐíÓû§²»±Ø·ÔÄÍêÕû¸öÊé¾ÍÄÜѸËÙµØÕÒµ½ËùÐèÒªµÄÐÅÏ¢¡£ÔÚÊý¾Ý¿âÖУ¬Ë÷ÒýÒ²ÔÊÐíÊý¾Ý¿â³ÌÐòѸËÙµØÕÒµ½±íÖеÄÊý¾Ý£¬¶ø²»±ØɨÃèÕû¸öÊý¾Ý¿â¡£ ¶þ¡¢Ë÷ÒýµÄÌصã 1.Ë÷Òý¿ÉÒÔ¼Ó¿ìÊý¾Ý¿âµÄ¼ìË÷ËÙ¶È
2.Ë÷Òý½µµÍÁËÊý¾Ý¿â²åÈë¡¢Ð޸ġ¢É¾³ýµÈά»¤ÈÎÎñµÄËÙ¶È 3.Ë÷Òý´´½¨ÔÚ±íÉÏ£¬²»ÄÜ´´½¨ÔÚÊÓͼÉÏ 4.Ë÷Òý¼È¿ÉÒÔÖ±½Ó´´½¨£¬Ò²¿ÉÒÔ¼ä½Ó´´½¨
5.¿ÉÒÔÔÚÓÅ»¯Òþ²ØÖУ¬Ê¹ÓÃË÷Òý 6.ʹÓòéѯ´¦ÀíÆ÷Ö´ÐÐSQLÓï¾ä£¬ÔÚÒ»¸ö±íÉÏ£¬Ò»´ÎÖ»ÄÜʹÓÃÒ»¸öË÷Òý
7.ÆäËû Èý¡¢Ë÷ÒýµÄÓŵã 1.´´½¨Î¨Ò»ÐÔË÷Òý£¬±£Ö¤Êý¾Ý¿â±íÖÐÿһÐÐÊý¾ÝµÄΨһÐÔ 2.´ó´ó¼Ó¿ìÊý¾ÝµÄ¼ìË÷Ëٶȣ¬ÕâÒ²ÊÇ´´½¨Ë÷ÒýµÄ×îÖ÷ÒªµÄÔÒò 3.¼ÓËÙ±íºÍ±íÖ®¼äµÄÁ¬½Ó£¬ÌرðÊÇÔÚʵÏÖÊý¾ÝµÄ²Î¿¼ÍêÕûÐÔ·½ÃæÌرðÓÐÒâÒå¡£ 4.ÔÚʹÓ÷Ö×éºÍÅÅÐò×Ó¾ä½øÐÐÊý¾Ý¼ìË÷ʱ£¬Í¬Ñù¿ÉÒÔÏÔÖø¼õÉÙ²éѯÖзÖ×éºÍÅÅÐòµÄʱ¼ä¡£ 5.ͨ¹ýʹÓÃË÷Òý£¬¿ÉÒÔÔÚ²éѯµÄ¹ý³ÌÖÐʹÓÃÓÅ»¯Òþ²ØÆ÷£¬Ìá¸ßϵͳµÄÐÔÄÜ¡£ ËÄ¡¢Ë÷ÒýµÄȱµã 1.´´½¨Ë÷ÒýºÍά»¤Ë÷ÒýÒªºÄ·Ñʱ¼ä£¬ÕâÖÖʱ¼äËæ×ÅÊý¾ÝÁ¿µÄÔö¼Ó¶øÔö¼Ó 2.Ë÷ÒýÐèÒªÕ¼ÎïÀí¿Õ¼ä£¬³ýÁËÊý¾Ý±íÕ¼Êý¾Ý¿Õ¼äÖ®Í⣬ÿһ¸öË÷Òý»¹ÒªÕ¼Ò»¶¨µÄÎïÀí¿Õ¼ä£¬Èç¹ûÒª½¨Á¢¾Û´ØË÷Òý£¬ÄÇôÐèÒªµÄ¿Õ¼ä¾Í»á¸ü´ó 3.µ±¶Ô±íÖеÄÊý¾Ý½øÐÐÔö¼Ó¡¢É¾³ýºÍÐ޸ĵÄʱºò£¬Ë÷ÒýÒ²Òª¶¯Ì¬µÄά»¤£¬½µµÍÁËÊý¾ÝµÄά»¤ËÙ¶È Îå¡¢Ë÷Òý·ÖÀà 1.Ö±½Ó´´½¨Ë÷ÒýºÍ¼ä½Ó´´½¨Ë÷Òý Ö±½Ó´´½¨Ë÷Òý£º CREATE INDEX mycolumn_index ON mytable (myclumn) ¼ä½Ó´´½¨Ë÷Òý£º¶¨ÒåÖ÷¼üÔ¼Êø»òÕßΨһÐÔ¼üÔ¼Êø£¬¿ÉÒÔ¼ä½Ó´´½¨Ë÷Òý 2.ÆÕͨË÷ÒýºÍΨһÐÔË÷Òý ÆÕͨË÷Òý£ºCREATE INDEX mycolumn_index ON mytable (myclumn) ΨһÐÔË÷Òý£º±£Ö¤ÔÚË÷ÒýÁÐÖеÄÈ«²¿Êý¾ÝÊÇΨһµÄ£¬¶Ô¾Û´ØË÷ÒýºÍ·Ç¾Û´ØË÷Òý¶¼¿ÉÒÔʹÓà CREATE UNIQUE COUSTERED INDEX myclumn_cindex ON mytable(mycolumn) 3.µ¥¸öË÷ÒýºÍ¸´ºÏË÷Òý µ¥¸öË÷Òý£º¼´·Ç¸´ºÏË÷Òý ¸´ºÏË÷Òý£ºÓÖ½Ð×éºÏË÷Òý£¬ÔÚË÷Òý½¨Á¢Óï¾äÖÐͬʱ°üº¬¶à¸ö×Ö¶ÎÃû£¬×î¶à16¸ö×ֶΠCREATE INDEX name_index ON username(firstname,lastname) 4.¾Û´ØË÷ÒýºÍ·Ç¾Û´ØË÷Òý(¾Û¼¯Ë÷Òý£¬Èº¼¯Ë÷Òý) ¾Û´ØË÷Òý£ºÎïÀíË÷Òý£¬Óë»ù±íµÄÎïÀí˳ÐòÏàͬ£¬Êý¾ÝÖµµÄ˳Ðò×ÜÊÇ°´ÕÕ˳ÐòÅÅÁÐ CREATE CLUSTERED INDEX mycolumn_cindex ON mytable(mycolumn) WITH ALLOW_DUP_ROW(ÔÊÐíÓÐÖظ´¼Ç¼µÄ¾Û´ØË÷Òý) ·Ç¾Û´ØË÷Òý£ºCREATE UNCLUSTERED INDEX mycolumn_cindex ON mytable(mycolumn) Áù¡¢Ë÷ÒýµÄʹÓà 1.µ±×Ö¶ÎÊý¾Ý¸üÐÂƵÂʽϵͣ¬²éѯʹÓÃƵÂʽϸ߲¢ÇÒ´æÔÚ´óÁ¿Öظ´ÖµÊǽ¨ÒéʹÓþ۴ØË÷Òý 2.¾³£Í¬Ê±´æÈ¡¶àÁУ¬ÇÒÿÁж¼º¬ÓÐÖظ´Öµ¿É¿¼Âǽ¨Á¢×éºÏË÷Òý 3.¸´ºÏË÷ÒýµÄÇ°µ¼ÁÐÒ»¶¨ºÃ¿ØÖƺ㬷ñÔòÎÞ·¨Æðµ½Ë÷ÒýµÄЧ¹û¡£Èç¹û²éѯʱǰµ¼Áв»ÔÚ²éѯÌõ¼þÖÐÔò¸Ã¸´ºÏË÷Òý²»»á±»Ê¹Óá£Ç°µ¼ÁÐÒ»¶¨ÊÇʹÓÃ×îƵ·±µÄÁÐ 4.¶à±í²Ù×÷ÔÚ±»Êµ¼ÊÖ´ÐÐÇ°£¬²éѯÓÅ»¯Æ÷»á¸ù¾ÝÁ¬½ÓÌõ¼þ£¬Áгö¼¸×é¿ÉÄܵÄÁ¬½Ó·½°¸²¢´ÓÖÐÕÒ³öϵͳ¿ªÏú×îСµÄ×î¼Ñ·½°¸¡£Á¬½ÓÌõ¼þÒª³ä·Ý¿¼ÂÇ´øÓÐË÷ÒýµÄ±í¡¢ÐÐÊý¶àµÄ±í£»ÄÚÍâ±íµÄÑ¡Ôñ¿ÉÓɹ«Ê½£ºÍâ²ã±íÖеÄÆ¥ÅäÐÐÊý*ÄÚ²ã±íÖÐÿһ´Î²éÕҵĴÎÊýÈ·¶¨£¬³Ë»ý×îСΪ×î¼Ñ·½°¸ 5.where×Ó¾äÖжÔÁеÄÈκβÙ×÷½á¹û¶¼ÊÇÔÚsqlÔËÐÐʱÖðÁмÆËãµÃµ½µÄ£¬Òò´ËËü²»µÃ²»½øÐбíËÑË÷£¬¶øûÓÐʹÓøÃÁÐÉÏÃæµÄË÷Òý£»Èç¹ûÕâЩ½á¹ûÔÚ²éѯ±àÒëʱ¾ÍÄܵõ½£¬ÄÇô¾Í¿ÉÒÔ±»sqlÓÅ»¯Æ÷ÓÅ»¯£¬Ê¹ÓÃË÷Òý£¬±ÜÃâ±íËÑË÷(Àý£ºselect * from record where substring(card_no,1,4)=¡¯5378¡¯ && select * from record where card_no like ¡¯5378%¡¯)ÈκζÔÁеIJÙ×÷¶¼½«µ¼Ö±íɨÃ裬Ëü°üÀ¨Êý¾Ý¿âº¯Êý¡¢¼ÆËã±í´ïʽµÈµÈ£¬²éѯʱҪ¾¡¿ÉÄܽ«²Ù×÷ÒÆÖÁµÈºÅÓÒ±ß 6.whereÌõ¼þÖеġ¯in¡¯ÔÚÂß¼ÉÏÏ൱ÓÚ¡¯or¡¯£¬ËùÒÔÓï·¨·ÖÎöÆ÷»á½«in ('0','1')ת»¯Îªcolumn='0' or column='1'À´Ö´ÐС£ÎÒÃÇÆÚÍûËü»á¸ù¾Ýÿ¸öor×Ó¾ä·Ö±ð²éÕÒ£¬ÔÙ½«½á¹ûÏà¼Ó£¬ÕâÑù¿ÉÒÔÀûÓÃcolumnÉϵÄË÷Òý£»µ«Êµ¼ÊÉÏËüÈ´²ÉÓÃÁË"or²ßÂÔ "£¬¼´ÏÈÈ¡³öÂú×ãÿ¸öor×Ó¾äµÄÐУ¬´æÈëÁÙʱÊý¾Ý¿âµÄ¹¤×÷±íÖУ¬ÔÙ½¨Á¢Î¨Ò»Ë÷ÒýÒÔÈ¥µôÖظ´ÐУ¬×îºó´ÓÕâ¸öÁÙʱ±íÖмÆËã½á¹û¡£Òò´Ë£¬Êµ¼Ê¹ý³ÌûÓÐÀûÓà columnÉÏË÷Òý£¬²¢ÇÒÍê³Éʱ¼ä»¹ÒªÊÜtempdbÊý¾Ý¿âÐÔÄܵÄÓ°Ïì¡£in¡¢or×Ӿ䳣»áʹÓù¤×÷±í£¬Ê¹Ë÷ÒýʧЧ£»Èç¹û²»²úÉú´óÁ¿Öظ´Öµ£¬¿ÉÒÔ¿¼ÂÇ°Ñ×Ó¾ä²ð¿ª£»²ð¿ªµÄ×Ó¾äÖÐÓ¦¸Ã°üº¬Ë÷Òý 7.ÒªÉÆÓÚʹÓô洢¹ý³Ì£¬Ëüʹsql±äµÃ¸ü¼ÓÁé»îºÍ¸ßЧ |