SQLÓαêÔÀíºÍʹÓ÷½·¨
SQLÓαêÔÀíºÍʹÓ÷½·¨
Êý¾Ý¿â¿ª·¢¹ý³ÌÖУ¬µ±Äã¼ìË÷µÄÊý¾ÝÖ»ÊÇÒ»Ìõ¼Ç¼ʱ£¬ÄãËù±àдµÄÊÂÎñÓï¾ä´úÂëÍùÍùʹÓÃSELECT INSERT Óï¾ä¡£µ«ÊÇÎÒÃdz£³£»áÓöµ½ÕâÑùÇé¿ö£¬¼´´Óijһ½á¹û¼¯ÖÐÖðÒ»µØ¶ÁÈ¡Ò»Ìõ¼Ç¼¡£ÄÇôÈçºÎ½â¾öÕâÖÖÎÊÌâÄØ£¿ÓαêΪÎÒÃÇÌṩÁËÒ»ÖÖ¼«ÎªÓÅÐãµÄ½â¾ö·½°¸¡£
1.1 ÓαêºÍÓαêµÄÓŵã
ÔÚÊý¾Ý¿âÖУ¬ÓαêÊÇÒ»¸öÊ®·ÖÖØÒªµÄ¸ÅÄî¡£ÓαêÌṩÁËÒ»ÖÖ¶Ô´Ó±íÖмìË÷³öµÄÊý¾Ý½øÐвÙ×÷µÄÁé»îÊֶΣ¬¾Í±¾ÖʶøÑÔ£¬Óαêʵ¼ÊÉÏÊÇÒ»ÖÖÄÜ´Ó°üÀ¨¶àÌõÊý¾Ý¼Ç¼µÄ½á¹û¼¯ÖÐÿ´ÎÌáÈ¡Ò»Ìõ¼Ç¼µÄ»úÖÆ¡£Óαê×ÜÊÇÓëÒ»ÌõT_SQL Ñ¡ÔñÓï¾äÏà¹ØÁªÒòΪÓαêÓɽá¹û¼¯£¨¿ÉÒÔÊÇÁãÌõ¡¢Ò»Ìõ»òÓÉÏà¹ØµÄÑ¡ÔñÓï¾ä¼ìË÷³öµÄ¶àÌõ¼Ç¼£©ºÍ½á¹û¼¯ÖÐÖ¸ÏòÌض¨¼Ç¼µÄÓαêλÖÃ×é³É¡£µ±¾ö¶¨¶Ô½á¹û¼¯½øÐд¦Àíʱ£¬±ØÐëÉùÃ÷Ò»¸öÖ¸Ïò¸Ã½á¹û¼¯µÄÓαꡣÈç¹ûÔø¾Óà C ÓïÑÔд¹ý¶ÔÎļþ½øÐд¦ÀíµÄ³ÌÐò£¬ÄÇôÓαê¾ÍÏñÄú´ò¿ªÎļþËùµÃµ½µÄÎļþ¾ä±úÒ»Ñù£¬Ö»ÒªÎļþ´ò¿ª³É¹¦£¬¸ÃÎļþ¾ä±ú¾Í¿É´ú±í¸ÃÎļþ¡£¶ÔÓÚÓαê¶øÑÔ£¬ÆäµÀÀíÊÇÏàͬµÄ¡£¿É¼ûÓαêÄܹ»ÊµÏÖ°´Ó봫ͳ³ÌÐò¶ÁȡƽÃæÎļþÀàËƵķ½Ê½´¦ÀíÀ´×Ô»ù´¡±íµÄ½á¹û¼¯£¬´Ó¶ø°Ñ±íÖÐÊý¾ÝÒÔƽÃæÎļþµÄÐÎʽ³ÊÏÖ¸ø³ÌÐò¡£
ÎÒÃÇÖªµÀ¹ØϵÊý¾Ý¿â¹ÜÀíϵͳʵÖÊÊÇÃæÏò¼¯ºÏµÄ£¬ÔÚMS SQL SERVER Öв¢Ã»ÓÐÒ»ÖÖÃèÊö±íÖе¥Ò»¼Ç¼µÄ±í´ïÐÎʽ£¬³ý·ÇʹÓÃwhere ×Ó¾äÀ´ÏÞÖÆÖ»ÓÐÒ»Ìõ¼Ç¼±»Ñ¡ÖС£Òò´ËÎÒÃDZØÐë½èÖúÓÚÓαêÀ´½øÐÐÃæÏòµ¥Ìõ¼Ç¼µÄÊý¾Ý´¦Àí¡£
Óɴ˿ɼû£¬ÓαêÔÊÐíÓ¦ÓóÌÐò¶Ô²éѯÓï¾äselect ·µ»ØµÄÐнá¹û¼¯ÖÐÿһÐнøÐÐÏàͬ»ò²»Í¬µÄ²Ù×÷£¬¶ø²»ÊÇÒ»´Î¶ÔÕû¸ö½á¹û¼¯½øÐÐͬһÖÖ²Ù×÷£»Ëü»¹Ìṩ¶Ô»ùÓÚÓαêλÖöø¶Ô±íÖÐÊý¾Ý½øÐÐɾ³ý»ò¸üеÄÄÜÁ¦£»¶øÇÒ£¬ÕýÊÇÓαê°Ñ×÷ΪÃæÏò¼¯ºÏµÄÊý¾Ý¿â¹ÜÀíϵͳºÍÃæÏòÐеijÌÐòÉè¼ÆÁ½ÕßÁªÏµÆðÀ´£¬Ê¹Á½¸öÊý¾Ý´¦Àí·½Ê½Äܹ»½øÐйµÍ¨¡£
1.2 ÓαêÖÖÀà
MS SQL SERVER Ö§³ÖÈýÖÖÀàÐ͵ÄÓα꣺Transact_SQL Óα꣬API ·þÎñÆ÷ÓαêºÍ¿Í»§Óαꡣ
£¨1£© Transact_SQL Óαê
Transact_SQL ÓαêÊÇÓÉDECLARE CURSOR Óï·¨¶¨Òå¡¢Ö÷ÒªÓÃÔÚTransact_SQL ½Å±¾¡¢´æ´¢¹ý³ÌºÍ´¥·¢Æ÷ÖС£Transact_SQL ÓαêÖ÷ÒªÓÃÔÚ·þÎñÆ÷ÉÏ£¬ÓÉ´Ó¿Í»§¶Ë·¢Ë͸ø·þÎñÆ÷µÄTransact_SQL Óï¾ä»òÊÇÅú´¦Àí¡¢´æ´¢¹ý³Ì¡¢´¥·¢Æ÷ÖеÄTransact_SQL ½øÐйÜÀí¡£ Transact_SQL Óα겻֧³ÖÌáÈ¡Êý¾Ý¿é»ò¶àÐÐÊý¾Ý¡£
£¨2£© API Óαê
API ÓαêÖ§³ÖÔÚOLE DB£¬ ODBC ÒÔ¼°DB_library ÖÐʹÓÃÓα꺯Êý£¬Ö÷ÒªÓÃÔÚ·þÎñÆ
Ïà¹ØÎĵµ£º
ÔÌù£ºhttp://topic.csdn.net/u/20100412/11/a4ea520e-7dd0-44d2-98bb-9f62f0ed6160.html?21233
--------------------------------------------------------------------------
-- Author : htl258(Tony)
-- Date : 2010-04-14 06:02:36
-- Version:Microsoft SQL Server 2008 (RTM) - 1 ......
select name as ¿âÃû from master..sysdatabases where dbid>=7 »ñµÃÊý¾Ý¿âÃû³Æ
select * from sysobjects where xtype='u' or xtype='v' ²éѯÊý¾Ý¿âÀïËùÓбíµÄsqlÓï¾ä£¡
select name from sysobjects where type='u' ²éѯһ¸ö¿ ......
¶ÔInºÍexistsµÄÐÔÄܽøÐбȽϣ¬Ê×ÏÈÒªÖªµÀËüÃÇÁ½ÕßµÄÇø±ð¡£
in: È·¶¨¸ø¶¨µÄÖµÊÇ·ñÓë×Ó²éѯÖеÄÖµ»òÁбíÖеÄÖµÏàÆ¥Åä¡£
exists: Ö¸¶¨Ò»¸ö×Ó²éѯ£¬¼ì²âÐÐÊÇ·ñ´æÔÚ¡£
¿É·ÖÎöËüÃǵIJéѯÓï¾äÀ´µÃ³öÕæʵµÄ²î±ð:
in
±ÈÈçSelect * from t1 where x in ( select y from t2 )
Ö´ÐеĹý³ÌÏ൱ÓÚ:
select *
from t1, ( ......
ʹÓùýSQL ServerµÄÈËÓ¦¸Ã¶¼Çå³þ£¬SQL Server³£ÓõÄÓÐÁ½ÖÖÈÏÖ¤·½Ê½£¬Ò»ÖÖÊDZ¾µØϵͳÕË»§ÈÏÖ¤£¨Windows Authentication £©£¬Ò»ÖÖÊÇʹÓÃÓû§ÃûºÍÃÜÂ루SQL Server Authentication £©£¬µÚ¶þÖÖÈÏÖ¤·½Ê½±ØÐëÆôÓÃSQL ServerµÄ»ìºÏģʽ¡£
¡¡¡¡1.Windows AuthenticationÁ¬½Ó²¿·Ö´úÂë¶Î£º
<?php
$serverName = "(local)";
$co ......