- ©«¤l
- 128
- ¥DÃD
- 13
- ºëµØ
- 1
- ¿n¤À
- 118
- ÂI¦W
- 0
- §@·~¨t²Î
- WinXP
- ³nÅ骩¥»
- Office2003
- ¾\ŪÅv
- 50
- ©Ê§O
- ¨k
- ¨Ó¦Û
- ¥|¤t¦¨³£ÊT崃
- µù¥U®É¶¡
- 2010-9-13
- ³Ì«áµn¿ý
- 2017-5-12
|
¤T¡BÌÛ³y©M´£¥æ¬d询
¡@¡@¦bÌÛ³y¬d询ªº时Ô¡An·d²M·¡为¤°¤\¥²须这¤\°µ¡B为¤°¤\¤£¯à¨º¤\°µ¬O¤@个«ÜÎ`杂ªº问题¡CµM¦Ó¡A¤@¨Ç°ò¥»ªº«ü导¤è针¯à够让ÌÛ³y°ª®Ä¬d询ªº过µ{§ó¥[¬y畅¡B轻ªQ¡C¤@¯ë¦a¡A§A¤£应该让¬d询®ö费ªA务¾¹时间¡C¤U±¤L个§Þ¥©¯à够帮§U§AÌÛ³y¥X§ó¦n¡B§ó°ª®Äªº¬d询¡C
¡@¡@¤£n强¨îSQL Server¨C¦¸执¦æ¬d询ªº时Ô«·s编译©MÌÛ³y¬d询执¦æ计¦E¡CÁקK这Ïú«Î`¾Þ§@ªº¤@Ïú简单¤èªk¬O¨Ï¥Î带¦³参数ªº¦s储过µ{¡Cª`·N尽¶q¤£n¨Ï¥ÎADO Command对¶HªºPrepare属©Ê¡X¡X¦³时¥¦¤£¯à¥¿Ṳ́u§@¡C¦pªG¨Ï¥Î¦s储过µ{¡A§A还¥i¥H³q过®ø°£¤£¥²nªº¡§¨ü¼v响¦æ数¡¨ªð¦^È进¤@¨B´£°ªADO©Ê¯à¡X¡X¥u»Ý¦b¦s储过µ{¤¤¥[¤JSET NOCOUNT ON´N¥i¥H¤F¡C
¡@¡@尽¶q减¤ÖÉOªA务¾¹ªº³q«H¦¸数¡C¦pªG§A¦³¤L个¬Û关ªº¾Þ§@n执¦æ¡A请§â¥¦们¦X¦}为¤@个¦s储过µ{¡A©ÎªÌ¬O¤@个¥i¥H¦bªA务¾¹¤W§@为脚¥»执¦æªºÎ`¦X¬d询¡CÁקK¨Ï¥Î¤èªk¡]¤ñ¦pRefresh¡^©M¤£Óì当ªºParameters¶°¦X¤Þ¥Î¡A¥¦们会强¨îADO¼W¥[额¥~ªºªA务¾¹³q«H过µ{¡C
¡@¡@¦b«È户Éó/ªA务¾¹应¥Î¤¤¡A¥uÌÛ³yCommand对¶H¤@¦¸¡A¦Ó¤£¬O¨C¦¸¨Ï¥ÎCommand对¶Hªº时Ô«·sÌÛ³y¡C§A¥i¥H«·s设¸mCommandªº参数È¡AµM¦Z¦b»Ýn时执¦æ¥¦¡C
¡@¡@当¬d询ªð¦^ªº¤£¬O¤@个记录¶°时¡AÚÌ«O¨Ï¥Î¤FadExecuteNoRecords选项¡A§i诉ADO¶V过©Ò¦³¨º¨Ç¥Î来±µ¦¬©MÌÛ³y记录¶°¡]Recordset®æ¦¡¡^ªº¥N码¡C§A¥i¥H§âadExecuteNoRecords选项传递给Execute¤èªk¡A©Î§â¥¦§@为Commandªº选项¡C
¡@¡@执¦æªð¦^简单记录¶°ªº¦s储过µ{时¡A¤£n¨Ï¥ÎCommand对¶H¡C©Ò¦³ªº¦s储过µ{¡]¥H¤ÎCommand对¶H¡^¥i¥H§@为Connection对¶HªºCOM¤èªk¥X现¡C让¦s储过µ{§@为Connection对¶Hªº¤èªk¥X现¦³着显µÛªº©Ê¯àɬ势¡A¦P时¥¦¤]简¤Æ¤F¥N码¡C尽ºÞ这Ïú§Þ术对¤_¨º¨Ç¦³Return StatusÈ©ÎOutput参数ªº¦s储过µ{没¦³¤°¤\帮§U¡A¦ý对¤_动§@¬d询¡]INSERT¡BDELETEµ¥¡^¥H¤Î¨º¨Çªð¦^¤@个©Î¦h个记录ªº¬d询来说¡A这Ïú§Þ术«Ü¦³¥Î¡C§â¦s储过µ{§@为Connectionªº¤èªk¤§¦Z¡A§A¥i¥H¥Î¤èªk参数ªº§Î¦¡传¤J¦s储过µ{ªº输¤J参数¡F¦pªG调¥Î¦s储过µ{ªð¦^¤F¤@个记录¶°¡A§A¥i¥H³q过¤èªk调¥Î¤¤³Ì¦Z¤@个参数¤Þ¥Î该Recordset¡C¨Ò¦p¡A¤U±ªºADO语¥y执¦æ¤@个¦W为¡§Fred¡¨ªº¦s储过µ{¡AFred¦s储过µ{¦³两个输¤J参数¡Aªð¦^¤@个Recordset¡G
MyConnection.Fred "InputArg1", 2, myRecordset
¡@¡@编写¥N码ªº时Ô¡A¤£n±H§Æ±æ¤_VBªº¦Û动§¹¦¨¥\¯à会§â¦s储过µ{©ÎCommand对¶H¦W¦r视为¦XªkªºConnection对¶Hªº¤èªk¡C¦b¥¿¦¡运¦æ¤§«e¡ACOM¤£会¸ÑªR这类¦W¦r¡C
¡@¡@°£«D绝对¥²n¡A§_则¤£nªð¦^记录¶°¡C当¥¿¦b执¦æªº¬d询ªð¦^记录时¡AADO´N会ÌÛ³y¤@个Recordset对¶H¡CÌÛ³yRecordset对¶Hªº开销«Ü¤j¡A¦]¦¹§A应该尽¶qÁקK¨Ï¥ÎRecordset对¶H¡Cª`·N¦³时Ô执¦æ¬d询虽µMªð¦^结ªG¡A¦ý¤£¬Oªð¦^记录¡C¨Ò¦p¡A§A¥i¥H³q过Return Status参数ªð¦^¾ã数È¡C¥t¥~¡A§A¥i¥Hªð¦^Output参数来´À¥N»ÝnÌÛ³yRecordset对¶Hªº记录¶°¡ASQL Server¤¹许ªð¦^ªºOutput参数¦h达1000个¡C
¡@¡@¥un¦³¥i¯à¡A请¥Î动§@¬d询¡]INSERT¡AUPDATE¡ADELETE©M执¦æ这¨Ç¾Þ§@ªº¦s储过µ{¡^´À¥N¥i§ó·sªºRecordset´å标¡C¦¹时¡A§A应该¨Ï¥ÎExecute¤èªk©M¥¦ªºadExecuteNoRecords选项¡AÚÌ«OADO¯à够ª¾¹D¬d询¤£»ÝnÌÛ³yRecordset对¶H¡C
¡@¡@°£«D¥²n¡A§_则¤£n请¨DªA务¾¹进¦æ±Æ§Ç¡C¤j¦h数±¡况¤U¡A对¤_¤@个Óì«×¤j¤pªºRecordset对¶H¡A当¥¦³Q发°e¨ì«È户ºÝ¤§¦Z¡A±Æ§Ç³t«×将§ó§Ö¡C¥t¥~¡A¦pªG让ADO«È户µ{§Ç±Æ§ÇRecordset¤¤ªº记录¡A则«È户应¥Îµ{§Ç¯à够«ö·Ó¥Î户选择ªº¦¸§Ç±Æ§Ç¡A从¦Ó´£°ª¤F灵¬¡©Ê¡C
¡@¡@¦b编写¬d询¤§«e¤F¸Ñ¯Á¤Þªº结ÌÛ¡C创«Ø¦XÓ쪺¯Á¤Þ¡A调¾ã¬d询ªº语ªk¥H§Q¥Î这¨Ç¯Á¤Þ¡A§A将¯à够´£°ª记录´£¨úªº³t«×¡CQuery Analyzer¯à够帮§U§A决©w¬O§_¦³¥²n²K¥[§ó¦hªº¯Á¤Þ¡C
¡@¡@¤£n¤@¦¸©Êªð¦^¤Ó¦hªº记录¡C«Ü¦h时Ô¡A®e¶q¤Ó¤jªº记录¶°会严«¦a¼v响应¥Îµ{§Çªº©Ê¯à¡C¥uªð¦^¨º¨Ç当«e§A»Ýnªº记录¡A¦pªG«È户µ{§Ç»Ýn§ó¦hªº记录¡A则¥H¦Z随时´£¨ú¡C³q过带¦³参数ªºWHERE¤l¥y¡A©ÎªÌ灵¬¡¦a运¥ÎTOP N¬d询¡A¨î¬d询ªºS围¡C
¡@¡@¤£nªð¦^¤Ó¦hªº¦C¡CÁקK¨Ï¥ÎSELECT *¡CSELECT *语¥y§i诉SQL Serverªð¦^©Ò¦³ªº¦C¡A¤£ºÞ实际¦s¦bªº¦C¦³¦h¤Ö¡C¥u选择¨º¨Ç§A»Ýnªº¦C¡A这样¡A当¦³¤H为ªí¼W¥[¤F§ó¦hªº¦C时¡A§A¤£会±o¨ì¤j±o¥X©_ªº结ªG¶°¡C
¡@¡@ÁקK¨Ï¥Î´å标¡C¦pªG§A¥²须¨Ï¥Î´å标¡A¨º¤\¤£n¨Ï¥Î¨º¨Ç©Ò»Ý资·½数¶q¶W过¥²nªº´å标类«¬¡C¦pªG没¦³¥²n¡A¤£nn¨D´å标´£¨Ñ滚动¡B§ó·s©M数Õu缓冲¯à¤O¡C
¡@¡@详细¦a§i诉ADO§A·Qn¥¦°µ¨Ç¤°¤\¡C¥´开Recordset©ÎªÌÌÛ³yCommand对¶H时¡A¤£n§Ñ¤F设¸mCommandType选项¡C¥¦ÁקK¤FADO¡§²q测¡¨§Aªº·N图¡A§A将¯à够减¤ÖÉOªA务¾¹ªº³q«H¡A¦Ó¥B¨Ï±o¥N码§ó¥[稳©w¡C
¡@¡@¥t¥~¡A学习¨Ï¥Î诊断¤u¨ã¡A测©w运¦æ¦bªA务¾¹¤Wªº¥N码©M应¥Îµ{§Çªº¥N码¥e¥Î¤F¦h¤Ö时间¡X¡X¥H¤Î这¨Ç时间ªá¦bþ¨½¡C¦b这¤è±¡ASQL Server Profiler¬O¤@个宝贵ªº¤u¨ã¡C¥¦¯à够阐©ú§Aªº¥N码¦bn¨DªA务¾¹°µ¨Ç¤°¤\¡A¯à够¦b¯ó²vÌÛ³yªº¬d询¤¤©Î对¤_错误选择ªº©R¥O属©Ê¬ð¥X显¥Ü¡C¥t¥~¡AQuery Analyzer还¯à够¥Î图¥Üªº¤è¦¡显¥Ü¥XSQL Server将¦p¦ó执¦æ¬d询¡A´£¥X§ï进¬d询ªº«Ø议¡A帮§U§A调¾ã¬d询¡CQuery Analyzer¬Æ¦Ü还¯à够执¦æ¥¦´£¥Xªº«Ø议¡]¨Ò¦p¡A²K¥[©ÎªÌ删°£¯Á¤Þ¡^¡A§A¥u»Ý点击¤@¤U«ö钮´N¥i¥H§¹¦¨¡C |
|