Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

¸ßЧSQL²éѯ֮Ë÷Òý£¨III£©


ÏÈ˵˵ÕâЩÎóÇø¡£Ëùν“ÎóÇø”£¬ÓÐһЩÊÇÐÂÊÖºÜÈÝÒ×·¸µÄ´íÎó»òÕߺÜÈÝÒ׺öÂÔµÄÎÊÌ⣬ÁíÍâһЩ£¬ÔòÊÇÏñ“ºÄ×Ó³ÔÁËÑλá±ä³Éòùòð”Ò»Ñù£¬ÈÃÎÒÃÇ´ÓС¾ÍÈÏΪÊÇÕýÈ·µÄÊÂÇé¡£ÈçÏ£º
1¡¢   ±íÉϲ»¹ÜÓõÃ×ÅÓò»×Å£¬¶¼¼Ó¸ö¾Û¼¯Ë÷Òý¡£
ÎÒÃÇÖªµÀ£¬±íÒÔÁ½ÖÖ·½Ê½×éÖ¯ÎïÀí´æ´¢£ºÓоۼ¯Ë÷ÒýµÄ“¾Û¼¯±í”£»Ã»Óоۼ¯Ë÷ÒýµÄ“¶Ñ”¡£ÔÚ¾Û¼¯±íÖУ¬Êý¾ÝÐа´ÕÕ¾Û¼¯Ë÷ÒýµÄ˳Ðò´æ´¢£¨ÕâÒ²ÊÇΪɶһÕűí×î¶àÖ»ÄÜÓÐÒ»¸ö¾Û¼¯Ë÷ÒýµÄÔ­Òò£©£»¶ÑÖУ¬Êý¾ÝÐеĴ洢¿ÉÒÔÈÏΪÊDz»È·¶¨µÄ¡£
ÔÚż¡¶Ð´ÓÐЧÂ浀 SQL ²éѯ£¨ II £©¡·ÖÐÔø¾­½éÉܹý DB ÒýÇæÈçºÎÔÚ¾Û¼¯±íÖÐͨ¹ý·Ç¾Û¼¯Ë÷Òý²éÕÒÄ¿±êÊý¾Ý£º´Ó·Ç¾Û¼¯Ë÷ÒýÊ÷¸ù¿ªÊ¼ seek £¬²éÕÒµ½Ä¿±êË÷ÒýÐУ¬È»ºóͨ¹ýË÷ÒýÐÐÉÏ´æ´¢µÄ¾Û¼¯Ë÷Òý¼üÖµ£¬ÅÀ¾Û¼¯Ë÷ÒýÊ÷£¬²¢×îÖÕͨ¹ý¾Û¼¯Ë÷ÒýÐÐÉϵÄÖ¸ÕëÄõ½Ä¿±êÊý¾Ý¡£
µ«ÊǶÑÉϵķǾۼ¯Ë÷Òý´æ´¢µÄ²»ÊǾۼ¯Ë÷Òý¼üÖµ£¬Ëü´æ´¢µÄÊÇÖ¸ÏòÄ¿±êÐеÄÖ¸Õë¡£Ò²¾ÍÊÇ˵£¬Èç¹ûÔÚͬÑùµÄ±íÊǶѣ¬Í¨¹ý·Ç¾Û¼¯Ë÷Òý seek Êý¾Ý½«Ê¡µôÅÀ¾Û¼¯Ë÷ÒýÊ÷µÄËðºÄ£¬¶ø¿ÉÒÔÖ±½Óͨ¹ý·Ç¾Û¼¯Ë÷ÒýÐÐÉϵÄÐÐÖ¸ÕëÖ±½ÓÄõ½Ä¿±êÊý¾Ý¡£Ò²¾ÍÊÇ˵£¬ÔÚijЩÇé¿öÏ£¬Ê¹ÓöѿÉÒÔÌá¸ßϵͳЧÂÊ¡£
Õâ¸ö“ijЩÇé¿ö”£¬¾ÍÊÇÄãµÄÐèÇó£¬ÄãµÄϵͳÐÐΪ¡£Ò»°ãÇé¿öÏ£¬ËùÓÐÈ˶ÔÒªÔÚʲôÑùµÄ×Ö¶ÎÉÏ´´½¨¾Û¼¯Ë÷Òý¶¼·Ç³£Á˽⣻µ«ÊDz»ÊÇËùÓеÄÈ˶¼¶ÔÓ¦¸ÃÔÚʲôÑùµÄϵͳÐÐΪÏ£¬²»´´½¨¾Û¼¯Ë÷ÒýÁ˽⡣¼ÙÉèÄãµÄ±íÖÐÓÐ×ֶΠcol1, col2,col3,col4 µÈµÈ£¬ col1 ¡¢ col2 µÄ·Ö²¼ÃܶȺܵ͡£Äã¹Û²ìÁËϵͳÐÐΪ£¬·¢ÏÖÒ»°ëµÄ²éѯÊÇ XXXX where col1 = YYYY £¬ÁíÒ»°ëµÄ²éѯÊÇ XXXX where col2 = YYYY ¡£ÕâÖÖÇé¿öÏ£¬Ê¹ÓöѾÍÊǸüºÃµÄÑ¡Ôñ¡£
2¡¢   primary key ¾ÍÊǾۼ¯Ë÷Òý¡£
primary key ÉÏÊǵÃÓÐË÷Òý£¬µ«ÊÇÕâ¸öË÷Òý¿É²»¼ûµÃÒ»¶¨µÃÊǾۼ¯Ë÷Òý¡£¾¡¹ÜÓï¾ä
create table testPK
(
           id int identity ( 1, 1) primary key ,
           fname varchar ( 64)
)
»áÔÚ id ÁÐÉÏ´´½¨¾Û¼¯Ë÷Òý¡£µ±È»£¬Ò»°ãÖ÷¼ü¶¼ÊǾۼ¯Ë÷Òý£¬µ«Ò²½ö½öÊÇ“Ò»°ã”¶øÒÑ¡£¸öÈ˸оõ£¬¾Û¼¯Ë÷ÒýµÄΨһĿ±ê¾ÍÊÇÊý¾Ý¼ìË÷£¬ËüÓ¦¸Ã½¨ÔÚʲô×Ö¶ÎÉÏ£¬ÍêÈ«ÓÉϵͳÐÐΪ¾ö¶¨¡£“Ò»°ãÖ÷¼ü¶¼ÊǾۼ¯Ë÷Òý”Ò²½ö½öÊÇÒòΪ¶àÊýÇé¿öÏ£¬ primary key ×Ö¶ÎÉϽ¨ËùÓиüÓÐÒæÓÚЧÂʶøÒÑ¡£
create table testPK
(
   


Ïà¹ØÎĵµ£º

SQL SERVER 2005 Óû§µÇ¼ʱ±¨18456´íÎó

[ÎÊÌâ]
×î½üͻȻ·¢ÏÖSQL SERVER Éí·ÝÑéÖ¤·½Ê½ÎÞ·¨Õý³£µÇ¼ÁË£¬×ÜÊDZ¨18456´íÎ󣬶øwindows Óû§¿ÉÒÔÕý³£µÇ¼¡£
[½â¾ö·½·¨]
ÔÚÍøÉÏËÑÁËһϣ¬ÄÇЩ·½·¨¶¼²»Äܽâ¾öÎÊÌ⣬ÓÚÊÇ»ØÏë×î½üÔÚ·þÎñÆ÷ÉÏ×öµÄһЩ²Ù×÷£ºÒ»¡¢¸ü¸Ä»úÆ÷Ãû³Æ£»¶þ¡¢Õë¶ÔÈä³æ²¡¶¾½Ï¶à£¬¹Ø±ÕÁËһЩDZÔÚÍþв¶Ë¿ÚÈç135¡¢445¡¢137£º139¡£
ÓÚÊÇÏȻָ´»úÆ÷Ãû³Æ£¬ ......

SQL ServerÈÕÆÚ¼ÆËã

ͨ³££¬ÄãÐèÒª»ñµÃµ±Ç°ÈÕÆںͼÆËãһЩÆäËûµÄÈÕÆÚ£¬ÀýÈ磬ÄãµÄ³ÌÐò¿ÉÄÜÐèÒªÅжÏÒ»¸öÔµĵÚÒ»Ìì»òÕß×îºóÒ»Ìì¡£ÄãÃǴ󲿷ÖÈË´ó¸Å¶¼ÖªµÀÔõÑù°ÑÈÕÆÚ½øÐзָÄê¡¢Ô¡¢Èյȣ©£¬È»ºó½ö½öÓ÷ָî³öÀ´µÄÄê¡¢Ô¡¢ÈյȷÅÔÚ¼¸¸öº¯ÊýÖмÆËã³ö×Ô¼ºËùÐèÒªµÄÈÕÆÚ£¡ÔÚÕâƪÎÄÕÂÀÎÒ½«¸æËßÄãÈçºÎʹÓÃDATEADDºÍDATEDIFFº¯ÊýÀ´¼ÆËã³öÔÚÄãµÄ³ÌÐòÖ ......

SQLÓï¾ä£º²éѯÊý¾Ý¿âÖÐËùÓзÇϵͳ±íµÄÐÅÏ¢

SELECT
       (case when a.colorder=1 then d.name else '' end)±íÃû,
       a.colorder ×Ö¶ÎÐòºÅ,
       a.name ×Ö¶ÎÃû,
       (case when COLUMNPROPERTY( a.id,a.name,'IsIdentity ......

SQL ÖÐ Delete¡¢Truncate¡¢DropÇø±ð

ɾ³ý±í¼Ç¼£¬¿ìËÙɾ³ý±í¼Ç¼£¬É¾³ý±íÕâЩÓï¾äÏàÐÅ´ó¼Ò¶¼»á£¬ÏÂÃæÕûÀíÒ»ÏÂTruncate¡¢delete¡¢dropÓ÷¨Çø±ð£º
Ïàͬµã
truncateºÍ²»´øwhere×Ó¾äµÄdelete, ÒÔ¼°drop¶¼»áɾ³ý±íÄÚµÄÊý¾Ý
²»Í¬µã:
1. truncateºÍ deleteֻɾ³ýÊý¾Ý²»É¾³ý±íµÄ½á¹¹(¶¨Òå)
    dropÓï¾ä½«É¾³ý±íµÄ½á¹¹±»ÒÀÀµµÄÔ¼Êø(constrain) ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ