SQL¶Ô³ÌÐòÐÔÄܵÄÓ°Ïì
¡¾ÏÈ˼¿¼Ò»¸öÎÊÌ⣺Áû×ÓºÍϹ×ÓÔÚÒ»Æð»áÓÐʲô½á¹û£¿¡¿
×òÌìд³ÌÐò£¬ÓиöСģ¿éÊÇͨ¹ý·ÖÎöÊýÊ®ÍòÌõ¼Ç¼£¬ÓëÒì¹¹µÄÊý¾Ý±í½øÐбȶԣ¬ÕÒ³ö·ûºÏÌõ¼þµÄÐÅÏ¢¡£
ÔÚµÚÒ»Ìõ²éѯÖУ¬ÐèÒª²éѯËùÓмǼµÄÒ»¸ö×ֶΣ¬²¢ÌáÈ¡¸Ã×Ö¶ÎÖеĵÚ5ÖÁµÚ10¸ö×Ö·û´®£¬ÒªÓëÒì¹¹Êý¾Ý±í±È½ÏµÄ¾ÍÊÇÕâ¸ö×Ö´®¡£ÔÚ×î³õµÄ°æ±¾ÖУ¬¶ÔÓÚÐÔÄܲ¢Ã»ÓÐ×ö¸ü¶àµÄ¿¼ÂÇ£¬ÏÈ´ÓÊý¾Ý±íÖлñÈ¡ËùÓеļǼ×é³ÉµÄÊý¾Ý¼¯£¬×÷ΪĿ±êÊý¾Ý£¬ÔÙ´ÓÒì¹¹Êý¾Ý±íÖлñÈ¡Êý¾Ý¼¯×÷Ϊ±È¶ÔÊý¾Ý£¬È»ºóÔÚ³ÌÐòÖо¹ýÖÁÉÙÁ½´Î±éÀú£¬É¸Ñ¡³öÏëÒªµÄ½á¹û¡£ÔÚÕâ¸ö°æ±¾ÖУ¬Ð§Âʺܵ͡£±È¶ÔÊý¾Ý»ù±¾ÉϹ̶¨£¬Ç§°ÑÌõµÄÑù×Ó£¬Ä¿±êÊý¾ÝºÜ¶à£¬¶øÇÒ»áÔ½À´Ô½¶à¡£µ«ÐÔÄܵÄÆ¿¾±²¢²»ÊdzöÏÖÔÚ³ÌÐòÖжà´ÎµÄ±éÀú£¬ÕâЩ¶¼ÔÚÄÚ´æÖнøÐУ¬ÕâµãÊý¾ÝÁ¿ºÍËã·¨£¬¶ÔÓÚÄ¿Ç°µÄ·þÎñÆ÷À´ËµÕæµÄÊÇС²ËÒ»µú¡£¾²âÊÔ£¬ËäȻֻÓм¸Ê®ÍòÐеļǼ£¬²éѯʱ¼äÈ´ÐèÒª5ÃëÒÔÉÏ¡£
ÎÒÔÀ´µÄ˼·ÊÇ£¬ÒòΪµ£ÐÄSQLµÄÐÔÄÜ£¬°Ñ´Ó×Ö¶ÎÖнØÈ¡×Ö·û´®µÄ¼ÆËãÓÉSQLÒÆÖÁ³ÌÐòÖнøÐУ¬µ«Êµ¼ùÖ¤Ã÷£¬¶ÔÓÚ·µ»Ø´óÁ¿¼Ç¼µÄSQL£¬ÆäЧÂÊ·´¶ø¸üµÍÁË¡£ÓÚÊÇ£¬¸Ä±ä˼·£¬»¹ÊÇÀûÓÃSQL½øÐÐɸѡ£¬²¢¾¡Á¿¼õÉÙÊý¾ÝÁ¿£¬ÓÐÁËÀàËÆÏÂÃæÕâÒ»Ðмòµ¥µÄ²éѯ£º
select distinct substring([prodcode],5,10) pcode from [detail] order by pcode
ÔÚÕâ¶Î²éѯÖУ¬Ê×ÏÈÊÇÀûÓÃsubstringº¯Êý£¬ÔÚsqlÖоͷµ»ØÁËÒªÏëµÄ×Ö·û´®£¬×¢ÒâÕâÀïsubstringº¯ÊýºÍC#ÖеÄÇø±ð£¬ËüÊÇ´Ó1¿ªÊ¼Ë÷ÒýµÄ£¬¶øC#ÖÐÔòÊÇ´Ó0¿ªÊ¼£¨ÎÒÔÚ´Ë×ßÁËÍä·£¬Èç¹û´ÏÃ÷µÄÄãÔç¾ÍÖªµÀ£¬ÇëºöÂÔ£©¡£È»ºóÊÇÇ°ÃæÓиö¹Ø¼ü×Ödistinct£¬ÓÃÀ´Ïû³ýÖظ´µÄ¼Ç¼£¨ÕâÀï´æÔÚ´óÁ¿µÄÖظ´Öµ£©¡£Êµ¼ùÖ¤Ã÷£¬ËäÈ»Ôö¼ÓÁËÒ»¸ö½ØÈ¡×Ö·û´®µÄ¼ÆË㣬µ«ÓÉÓÚ·µ»ØµÄ¼Ç¼´ó´ó¼õÉÙ£¬ÕâÖÖÇé¿öÏ£¬Êý¾Ý¿â·þÎñÆ÷·µ»Ø½á¹ûµÄʱ¼äÌáÉýµ½0Ã룬Ҳ¾ÍÊÇ˵ÒѾÊǺÁÃ뼶ÁË£¬SSMS£¨=²éѯ·ÖÎöÆ÷£©¸øºöÂÔÁË¡£
ÖÚËùÖÜÖª£¬I/O¶Ô³ÌÐòÐÔÄܵÄÓ°ÏìÏ൱´ó£¬ÔÚÕâ¸öССµÄʵÀýÖÐÒ²ÄÜ¿´³öÕâÒ»µã¡£×ʼ£¬ÎÒÏ뵱ȻµÄÒÔΪ°Ñ¼ÆËãÒƵ½³ÌÐòÖÐÈ¥×ö£¬¼õÇáÒ»ÏÂÊý¾Ý¿âµÄ¸ºµ££¬Í¬Ê±Ìá¸ßÔËËãЧÂÊ£¬È´ºöÂÔÁËÕâ¸öÎÊÌâ¡£µ±SQL·µ»ØÁË´óÁ¿Êý¾Ý£¬ÕâЩÊý¾ÝÒª´ÓÒ»¸öµØ·½Òƶ¯µ½ÁíÒ»¸öµØ·½£¬´ÓÄ¿Ç°µÄÍøÂçÐÔÄÜÀ´¿´£¬µ¢ÎóµÄʱ¼ä¾ø¶ÔÊDz»¿ÉÒÔºöÂԵġ£
Õâ¸ö¹ÊʸæËßÎÒÃÇ£¬²»ÄÜÏ뵱Ȼ£¬×ö³ÌÐòÈç´Ë£¬×öÈκÎÊÂÇ鶼ÊÇÈç´Ë¡£
PS
£º×îºó²»µÃ²»ÓÖÒª·¢¸öÀÎɧÁË£¬¸Õ²ÅÌá½»µÄʱºò£¬²îµãÓÖ·¢ÉúÇ°¹¦¾¡ÆúµÄʶù£¬ÕýÎÄÎı¾¿òһƬ¿Õ°×£¬ºÍ×òÌìÌáµ½µÄÒ»Ñù¡£Ò²ÐíÊÇÚ¤Ú¤Ö®ÖÐÓÐÉñÁéÔÚ°ïÎÒ£¬ÔÚµãÌá½»°´Å¥Ö®Ç°µÄÄÇһ˲¼ä£¬ÎÒ´òÁ˸öÀäÕ½£¬°ÑÕâÒ»¶ÑÎÄ×Ö¸´ÖƵ½Á˼Çʱ¾
Ïà¹ØÎĵµ£º
ÊÓͼµÄ´´½¨¼°Ê¹ÓÃ(sql server 2005)
´´½¨Ò»¸öÐéÄâ±í£¬¸Ã±íÒÔÒ»ÖÖ±¸Ó÷½Ê½Ìṩһ¸ö»ò¶à¸ö±íÖеÄÊý¾Ý¡£CREATE VIEW ±ØÐëÊDzéѯÅú´¦ÀíÖеĵÚÒ»ÌõÓï¾ä¡£
Transact-SQL Óï·¨Ô¼¶¨
Óï·¨
CREATE VIEW [ schema_name . ] view_name [ (column [ ,...n ] ) ]
[ WITH <view_attribute> [ ,...n ] ]
AS s ......
SQL code
¶¯Ì¬sqlÓï¾ä»ù±¾Óï·¨
1 :ÆÕͨSQLÓï¾ä¿ÉÒÔÓÃExecÖ´ÐÐ
eg: Select * from tableName
Exec('select * from tableName')
Exec sp_executesql N'select * from tableName' -- Çë×¢Òâ×Ö·û´®Ç°Ò»¶¨Òª¼ÓN
2:×Ö¶ÎÃû£¬±íÃû£¬Êý¾Ý¿âÃûÖ®Àà×÷Ϊ±äÁ¿Ê±£¬±ØÐëÓö¯Ì¬SQL
eg:
declare @ ......
ÔÚSQLÓï¾äÓÅ»¯¹ý³ÌÖУ¬ÎÒÃǾ³£»áÓõ½hint,ÏÖ×ܽáÒ»ÏÂÔÚSQLÓÅ»¯¹ý³ÌÖг£¼ûOracle HINTµÄÓ÷¨£º
1. /*+ALL_ROWS*/
±íÃ÷¶ÔÓï¾ä¿éÑ¡Ôñ»ùÓÚ¿ªÏúµÄÓÅ»¯·½·¨,²¢»ñµÃ×î¼ÑÍÌÍÂÁ¿,ʹ×ÊÔ´ÏûºÄ×îС»¯.
ÀýÈç:
SELECT /*+ALL+_ROWS*/ EMP_NO,EMP_NAM,DAT_IN from BSEMPMS WHERE EMP_NO='SCOTT';
2. /*+FIRST_ROWS*/
±í ......
CLR¿ÉÒÔʵÏÖDMLºÍDDLÁ½ÖÖ´¥·¢ÐÎʽ£¬µ«ÊDZ¾ÈËÒ»°ã²»½¨ÒéʹÓÃCLRµÄ´¥·¢Æ÷£¬Ö÷ÒªÊÇ¿¼Âǵ½Ð§ÂÊÎÊÌâ¡£±ÈÈçÎÒÃÇʹÓÃtriggerÀ´ÊµÏÖ·¢mailµÈ²Ù×÷ʱ£¬¾ÍÒª¿¼ÂÇpop3»òÊÇsmtpµÈ´ýʱ¼ä£¬ÒòΪtrigger±¾Ê¾ÍÊǸöÊÂÎñ£¬Ò²¾ÍÊÇ˵£¬ÔÚsmtpµÈ´ýʱ¼äÒ²ËãÔÚÁËÕû¸öÊÂÎñÖУ¬ÕâÑù¾Í»á´ó´óÓ°ÏìЧÂÊ¡£
1.CLR DML´¥·¢Æ÷
DMLÖ¸µÄÊÇÊý¾Ý²Ù×÷ÓïÑÔ£¬Ò²¾Í ......
--> Title : SQL ServerÖ®·Ö²¼Ê½ÊÂÎñ
--> Author : wufeng4552
--> Date : 2009-11-11
SQL ServerÖ®·Ö²¼Ê½ÊÂÎñ
(Ò»)¸ÅÄî:
·Ö²¼Ê½ÊÂÎñÊÇÉæ¼°À´×ÔÁ½¸ö»ò¶à¸öÔ´µÄ×ÊÔ´µÄÊÂÎñ¡£Microsoft® SQL Server™ 2000Ö§³Ö·Ö²¼Ê½ÊÂÎñ£¬Ê¹Óû§µÃÒÔ´´½¨ÊÂÎñÀ´¸üжà¸öSQL ServerÊý¾Ý¿âºÍÆäËüÊý¾ÝÔ ......