SQL ServerË÷Òý¹ÜÀíÖ®Áù´óÌúÂÉ
ÔÎÄת×Ô:http://tech.it168.com/a2009/0218/265/000000265868.shtml
Ë÷ÒýÊÇÒÔ±íÁÐΪ»ù´¡µÄÊý¾Ý¿â¶ÔÏó¡£Ë÷ÒýÖб£´æ×űíÖÐÅÅÐòµÄË÷ÒýÁУ¬²¢ÇҼͼÁËË÷ÒýÁÐÔÚÊý¾Ý¿â±íÖеÄÎïÀí´æ´¢Î»Öã¬ÊµÏÖÁ˱íÖÐÊý¾ÝµÄÂß¼ÅÅÐò¡£Í¨¹ýË÷Òý£¬¿ÉÒÔ¼Ó¿ìÊý¾ÝµÄ²éѯËٶȺͼõÉÙϵͳµÄÏìӦʱ¼ä;¿ÉÒÔʹ±íºÍ±íÖ®¼äµÄÁ¬½ÓËٶȼӿ졣
µ«ÊÇ£¬²»ÊÇÔÚÈκÎʱºòʹÓÃË÷Òý¶¼Äܹ»´ïµ½ÕâÖÖЧ¹û¡£ÈôÔÚ²»Ç¡µ±µÄ³¡ºÏÏ£¬Ê¹ÓÃË÷Òý·´¶ø»áÊÂÓëԸΥ¡£ËùÒÔ£¬ÔÚSQL ServerÊý¾Ý¿âÖÐʹÓÃË÷ÒýµÄ»°£¬»¹ÊÇÐèÒª×ñÊØÒ»¶¨µÄ¹æÔò¡£
ÌúÂÉÒ»£ºÌìÏÂûÓÐÃâ·ÑµÄÎç²Í£¬Ê¹ÓÃË÷ÒýÊÇÐèÒª¸¶³ö´ú¼ÛµÄ
Ë÷ÒýµÄÓŵãÓÐÄ¿¹²¶Ã£¬µ«ÊÇ£¬È´ºÜÉÙÓÐÈ˹ØÐĹý²ÉÓÃË÷ÒýËùÐèÒª¸¶³öµÄ³É±¾¡£ÈôÊý¾Ý¿â¹ÜÀíÔ±Äܹ»¶ÔË÷ÒýËùÐèÒª¸¶³öµÄ´ú¼ÛÓÐÒ»¸ö³ä·ÖµÄÈÏʶ£¬Ò²¾Í²»»áÄÇôËæÒâµ½´¦½¨Á¢Ë÷ÒýÁË¡£
×ÐϸÊýÊý£¬Æäʵ½¨Á¢Ë÷ÒýµÄ´ú¼Û»¹ÊÇÂù´óµÄ¡£Èç´´½¨Ë÷ÒýºÍά»¤Ë÷Òý¶¼ÐèÒª»¨·Ñʱ¼äÓ뾫Á¦¡£ÌرðÊÇÔÚÊý¾Ý¿âÉè¼ÆµÄʱºò£¬Êý¾Ý¿â¹ÜÀíԱΪ±íÖеÄÄÄЩ×Ö¶ÎÐèÒª½¨Á¢Ë÷Òý£¬Òªµ÷ÑС¢ÒªÐµ÷¡£Èçµ±½¨ÓÐË÷ÒýµÄ±íÖеļͼÓÖÔö¼Ó¡¢É¾³ý¡¢Ð޸IJÙ×÷ʱ£¬Êý¾Ý¿âÒª¶ÔË÷Òý½øÐÐÖØе÷Õû¡£ËäÈ»Õâ¸ö¹¤×÷Êý¾Ý¿â×Ô¶¯»áÍê³É£¬µ«ÊÇ£¬ÐèÒªÏûºÄ·þÎñÆ÷µÄ×ÊÔ´¡£µ±±íÖеÄÊý¾ÝÔ½¶à£¬Õâ¸öÏûºÄµÄ×ÊÔ´Ò²¾ÍÔ½¶à¡£ÈçË÷ÒýÊÇÊý¾Ý¿âÖÐʵ¼Ê´æÔڵĶÔÏó£¬ËùÒÔ£¬Ã¿¸öË÷Òý¶¼»áÕ¼ÓÃÒ»¶¨µÄÎïÀí¿Õ¼ä¡£ÈôË÷Òý¶àÁË£¬²»µ«»áÕ¼ÓôóÁ¿µÄÎïÀí¿Õ¼ä£¬¶øÇÒ£¬Ò²»áÓ°Ïìµ½Õû¸öÊý¾Ý¿âµÄÔËÐÐÐÔÄÜ¡£
¿É¼û£¬Êý¾Ý¿â¹ÜÀíÔ±ÈôÒª²ÉÓÃË÷ÒýÀ´Ìá¸ßϵͳµÄÐÔÄÜ£¬×ÔÉíÈÔÈ»ÐèÒª¸¶³ö²»ÉٵĴú¼Û¡£Êý¾Ý¿â¹ÜÀíÔ±ÏÖÔÚÒª¿¼ÂǵľÍÊÇÈçºÎÔÚÕâÁ½¸öÖ®¼äÈ¡µÃÒ»¸ö¾ùºâ¡£»òÕß˵£¬ÕÒµ½Ò»¸ö»Ø±¨ÓëͶÈëµÄÁÙ½çµã¡£
ÌúÂɶþ£º¶ÔÓÚ²éѯÖкÜÉÙÉæ¼°µÄÁлòÕßÖظ´Öµ±È½Ï¶àµÄÁУ¬²»Òª½¨Á¢Ë÷Òý
ÔÚ²éѯµÄʱºò£¬Èç¹ûÎÒÃDz»°´Ä³¸ö×Ö¶ÎÈ¥²éѯ£¬ÔòÔÚÕâ¸ö×Ö¶ÎÉϽ¨Á¢Ë÷ÒýÒ²ÊÇÀË·Ñ¡£ÈçÏÖÔÚÓÐÒ»ÕÅÔ±¹¤ÐÅÏ¢±í£¬ÎÒÃÇ¿ÉÄÜ°´Ô±¹¤±àºÅ¡¢Ô±¹¤ÐÕÃû¡¢»òÕß³öÉíµØÈ¥²éѯԱ¹¤ÐÅÏ¢¡£µ«ÊÇ£¬ÎÒÃÇÍùÍù²»»á°´ÕÕÉí·ÝÖ¤ºÅÂëÈ¥²éѯ¡£ËäÈ»Õâ¸öÉí·ÝÖ¤ºÅÂëÊÇΨһµÄ¡£´Ëʱ£¬¼´Ê¹ÔÚÕâ¸ö×Ö¶ÎÉϽ¨Á¢Ë÷Òý£¬Ò²²»Äܹ»Ìá¸ß²éѯµÄËٶȡ£Ïà·´£¬Ôö¼ÓÁËϵͳά»¤Ê±¼äºÍÕ¼ÓÃÁËϵͳ¿Õ¼ä¡£Õâ¼òÖ±¾ÍÊÇ°áÆðʯͷÔÒ×Ô¼ºµÄ½Åѽ¡£
ÁíÍ⣬ÈçÉÏÃæµÄÔ±¹¤ÐÅÏ¢±í£¬ÓÐЩ×Ö¶ÎÖظ´Öµ±È½Ï¶à¡£ÈçÐÔ±ð×Ö¶ÎÖ÷Òª¾ÍÊÇ“ÄД¡¢“Å®”;ְλ×Ö¶ÎÖÐÒ²ÊÇÓÐÏ޵ļ¸¸öÄÚÈÝ¡£´Ëʱ£¬ÔÚÕâЩ×Ö¶ÎÉÏÌí¼ÓË÷ÒýÒ²²»»áÏÔÖøµÄÔö¼Ó²éѯËٶȣ¬¼õÉÙÓû§
Ïà¹ØÎĵµ£º
SQL Server
¡¡¡¡´ÓÊý¾Ý¿â±íÖеĵÚMÌõ¼Ç¼¿ªÊ¼È¡NÌõ¼Ç¼£¬ÀûÓÃTop¹Ø¼ü×Ö£º×¢ÒâÈç¹ûSelectÓï¾äÖмÈÓÐtop£¬ÓÖÓÐorder by£¬ÔòÊÇ´ÓÅÅÐòºÃµÄ½á¹û¼¯ÖÐÑ¡Ôñ£º
¡¡¡¡SELECT *
¡¡¡¡from ( SELECT Top N *
¡¡¡¡from (SELECT Top (M + N - 1) * from& ......
±¸·Ý£º
A. ±¸·ÝÕû¸ö MyNwind Êý¾Ý¿â
˵Ã÷ MyNwind Êý¾Ý¿â½öÓÃÓÚÑÝʾ¡£
ÏÂÀý´´½¨ÓÃÓÚ´æ·Å MyNwind Êý¾Ý¿âÍêÕû±¸·ÝµÄÂß¼±¸·ÝÉ豸¡£
......
£¨1£©
Mcirosoft JET SQL ÖУ¬ÈÕÆÚÓÑ#’¶¨½ç¡£ÈÕÆÚÒ²¿ÉÒÔÓÃDatevalue()º¯ÊýÀ´´úÌæ¡£ÔڱȽÏ×Ö·ûÐ͵ÄÊý¾Ýʱ£¬Òª¼ÓÉϵ¥ÒýºÅ’’£¬Î²¿Õ¸ñÔڱȽÏÖб»ºöÂÔ¡£
Àý£º
WHERE OrderDate>#96-1-1#
Ò²¿ÉÒÔ±íʾΪ£º
WHERE OrderDate>Datevalue(‘1/1/96’)
ʹÓà NOT ±í´ïʽÇó·´¡£
Àý£ ......
USE Test
--Create 2 tables as an example
CREATE TABLE ExampleTable
(
[ID] int PRIMARY KEY
,[Name] nvarchar(256)
)
CREATE TABLE ExampleTable2
(
[ID] int PRIMARY KEY
,[Name] nvarchar(256)
)
----way1
SELECT *
from sys.objects [table]
WHERE
[Name] LIKE 'ExampleTable%'
FOR XML AUTO, ROOT ......
ORACLE ÖÐSQL Óï¾ä´óÖ¿ÉÒÔ·ÖΪ4´óÀà
1.DQL£¨data quary language Êý¾Ý²éѯÓïÑÔ£©
Êý¾Ý²éѯÓïÑÔDQL»ù±¾½á¹¹ÊÇÓÉSELECT×Ӿ䣬from×Ӿ䣬WHERE×Ó¾ä×é³É
2.DDL£¨data definition language Êý¾Ý¶¨ÒåÓïÑÔ£©
CREATE
ALTER
DROP
RENAME
TRUNCATE
3.DML£¨data manipulation language Êý¾Ý²Ù×ÝÓïÑÔ£©
INSERT
UPDATE
......