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

SQL SERVER¶¨Ê±×÷ÒµµÄÉèÖ÷½·¨

         SQL SERVER¶¨Ê±×÷ÒµµÄÉèÖ÷½·¨
תÌù×Ô£º http://www.cnblogs.com/stephencat/archive/2006/08/24/484918.html
 Èç¹ûÔÚSQL Server ÀïÐèÒª¶¨Ê±»òÕßÿ¸ôÒ»¶Îʱ¼äÖ´ÐÐij¸ö´æ´¢¹ý³Ì»ò3200×Ö·ûÒÔÄÚµÄSQLÓï¾äʱ,
¿ÉÒÔÓùÜÀí->SQL Server´úÀí->×÷ÒµÀ´ÊµÏÖ¡£
1¡¢¹ÜÀí->SQL Server´úÀí->×÷Òµ(°´Êó±êÓÒ¼ü)->н¨×÷Òµ->
2¡¢Ð½¨×÷ÒµÊôÐÔ(³£¹æ)->Ãû³Æ[×Ô¶¨Òå±¾´Î×÷ÒµµÄÃû³Æ]->ÆôÓõķ½¿òÄÚÊǹ´ºÅ->
·ÖÀà´¦¿ÉÑ¡ÔñÒ²¿ÉÓÃĬÈϵÄ[δ·ÖÀà(±¾µØ)]->ËùÓÐÕßĬÈÏΪµÇ¼SQL ServerÓû§[Ò²¿ÉÑ¡ÆäËüµÄµÇ¼]->
ÃèÊö[Ìîд±¾´Î¹¤×÷ÏêϸÃèÊöÄÚÈÝ]£»
[ ´´½¨×÷Òµ·ÖÀàµÄ²½Öè:
  SQL Server´úÀí->×÷Òµ->ÓÒ¼üÑ¡ËùÓÐÈÎÎñ->Ìí¼Ó¡¢Ð޸ġ¢É¾³ý ]
3¡¢Ð½¨×÷ÒµÊôÐÔ(²½Öè)->н¨->²½ÖèÃû[×Ô¶¨ÒåµÚÒ»²½ÖèÃû³Æ]->ÀàÐÍ[Transact-SQL(TSQL)½Å±¾]->
   Êý¾Ý¿â[Òª²Ù×÷µÄÊý¾Ý¿â]->ÃüÁî
   
     [ Èç¹ûÊǼòµ¥µÄSQLÖ±½Óд½øÈ¥¼´¿É£¬Ò²¿ÉÓôò¿ª°´Å¥ÊäÈëÒ»¸öÒÑдºÃµÄ*.sqlÎļþ
       Èç¹ûÒªÖ´Ðд洢¹ý³Ì£¬Ìî
       exec p_procedure_name v_parameter1,[ v_parameter2…v_parameterN]
      ]
      
   ->È·¶¨
   (Èç¹ûÓжà¸ö²½Ö裬¿ÉÒÔÔٴε÷ÓÃÏÂÃæµÄн¨°´Å¥£»Ò²¿ÉÒÔ¶ÔÒÑÓеĶà¸ö²½Öè²åÈë¡¢±à¼­¡¢É¾³ý)£»
4¡¢½¨×÷ÒµÊôÐÔ(µ÷¶È)->н¨µ÷¶È->Ãû³Æ[×Ô¶¨Òåµ÷¶ÈÃû³Æ]->ÆôÓõķ½¿òÄÚÊǹ´ºÅ->µ÷¶È->·´¸´³öÏÖ->
   ¸ü¸Ä[µ÷¶Èʱ¼ä±í]->È·¶¨
   
   (Èç¹ûÖ»Òª±£´æ´Ë×÷Òµ£¬²»Òª¶¨Ê±×ö¿ÉÒÔ°ÑÆôÓõķ½¿òÄÚÊǹ´ºÅÈ¥µô)£»
5¡¢½¨×÷ÒµÊôÐÔ(֪ͨ)->ÓÃĬÈϵÄ֪ͨ·½·¨¾ÍºÃ[µ±×÷ҵʧ°Üʱ£¬Ð´ÈëWindowsÓ¦ÓóÌÐòϵͳÈÕÖ¾] ->È·¶¨¡£
¸ú×÷ÒµÖ´ÐÐÏà¹ØµÄһЩSQL Server֪ʶ£º
SQLSERVERAGENT·þÎñ±ØÐëÕý³£ÔËÐУ¬Æô¶¯ËüµÄNTµÇ¼Óû§Òª¸úÆô¶¯SQL ServerÊý¾Ý¿âµÄNTµÇ¼Óû§Ò»Ö¡£
µã×÷ÒµÓÒ¼ü¿ÉÒԲ鿴×÷ÒµÖ´ÐеÄÀúÊ·¼Ç¼Çé¿ö£¬Ò²¿ÉÒÔÁ¢¼´Æô¶¯×÷ÒµºÍÍ£Ö¹×÷Òµ¡£
×î½üÔÚ¿´×÷ÒµÀúÊ·¼Ç¼ʱ,·¢ÏÖÓеÄ×÷Òµ¼Ç¼µÄÀúÊ·¼Ç¼¶à,ÓеÄ×÷Òµ¼Ç¼µÄ¼Ç¼µÄÀúÊ·¼Ç¼ÉÙ.
ÈçºÎ


Ïà¹ØÎĵµ£º

SQLÖÐÒÔÈÕÆÚΪÌõ¼þͳ¼Æ·½·¨

 /*ͳ¼ÆÿÌìÊý¾Ý×ÜÁ¿ÈýÖÖ·½·¨£º
        select convert(char(10),happentime ,120) as date ,count(1) from table1
        group by convert(char(10),happentime ,120) order by date desc
       s ......

¼¸ÌõÓÐÓõÄSqlÓï¾ä

1. Sql  ÑÓʱºòÖ´ÐÐ
a. ÈýÊ®ÃëºóÖ´ÐÐ WAITFOR DELAY  ºóÃæµÄÓï¾ä
WAITFOR DELAY '00:00:30'
b. 10:00·Ö¿ªÊ¼Ö´ÐкóÃæµÄ´úÂë
WAITFOR TIME '10:00';
 
2.  ÊÕËõÊý¾Ý¿â£¬Ê¹Æä¿ÕÓà¿Õ¼äΪ0%
DBCC SHRINKDATABASE (DataBaseName,0)
3.  È¡µÃÊý¾Ý¿âÎļþËùÔÚµÄÅÌ·û
declare @dirverNam ......

ÔÚSQL ServerÓ¦ÓÃÖÐʹÓÃOUTPUT×Ó¾ä

 ÏÖÔÚ´ó¶àÊýÃèÊöSQL Server 2005ÐÂÌØÐÔµÄÎÄÕ¶¼¹Ø×¢ÓÚ»ª¶ø²»ÊµµÄÌØÐÔ£¬ÈçSQLCLR»òXMLÊý¾ÝÀàÐÍ£¬¶ø¶ÔÐí¶àºÜºÃµÄÀϵÄT-SQLÓïÑԵĸĽøûÓеõ½Ó¦ÓеĹØ×¢¡£ÎÒÔø¾­´ÓÐí¶àDBA¿ÚÖÐÌýµ½ÁîËûÃǸüÐ˷ܵÄÊÇ¿´µ½T-SQLÓïÑԵĸĽø,¶ø²»ÊÇÄÇЩгöÏֺͷ¢²¼µÄ¹¦ÄÜ¡£¶ÔÓÚSQLÓïÑÔµÄÒ»¸öºÜÓÐÓõÄʵ¼Ê¸Ä½øÊÇOUTPUT×Ӿ䣬ËüÔÊÐí²éѯһ¸öÊý¾ ......

ÓÃSQL Server 2005 CTE¼ò»¯²éѯ

SQL Server 2005Òý½øÁËÒ»¸öºÜÓмÛÖµµÄеÄTransact-SQLÓïÑÔ×é¼þ£ºÒ»¸öͨÓñí±í´ïʽ£¨Common Table Expression£¬CTE£©£¬ËüÊÇÅÉÉú±íºÍÊÓͼµÄÒ»¸ö±ã½ÝµÄÌæ´ú¡£Í¨¹ýʹÓÃCTE£¬ÎÒÃÇ¿ÉÒÔ´´½¨Ò»¸öÃüÃû½á¹û¼¯À´ÔÚSELECT¡¢INSERT¡¢UPDATEºÍDELETEÓï¾äÖÐÒýÓ㬶øÎÞÐë±£´æ½á¹û¼¯½á¹¹µÄÈκÎÔªÊý¾Ý¡£ÔÚ±¾ÎÄÖУ¬ÎÒ½«²ûÊöÈçºÎÔÚSQL Server 2 ......

sql DATEPART£¨£©º¯Êý

cdateÊÇdatetimeÀàÐ͵Ä×Ö¶Î
ͳ¼ÆÒ»ÄêµÄÈçÏÂ
 select datepart(yy,cdate) as 'Ô·Ý',sum(cmoney) from consumption group by datepart(yy,cdate)
ͳ¼ÆÒ»ÔµÄÈçÏÂ
 select datepart(mm,cdate) as 'Ô·Ý',sum(cmoney) from consumption where datepart(yy,cdate)=2009 group by datepart(mm,cdate)
ͳ¼ÆÒ»ÖÜ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ