²âÊÔMSSQLÖÐSQLÓï¾äÖ´Ðл¨·ÑµÄʱ¼ä
selectÓï¾äÇ°¼Ó£º
declare @d datetime
set @d=getdate()
²¢ÔÚselectÓï¾äºó¼Ó£º
select [Óï¾äÖ´Ðл¨·Ñʱ¼ä(ºÁÃë)]=datediff(ms,@d,getdate())
ת×Ô£º¶¯Ì¬ÍøÖÆ×÷Ö¸ÄÏ www.knowsky.com
ÕâÊǼòÒ׵IJ鿴ִÐÐʱ¼äµÄ·½·¨¡£
===========================================£¨Ò»ÏÂÄÚÈÝת×Ô£º£Ã£Ó£Ä£Î£©
MSSQL ServerÖÐͨ¹ý²é¿´SQLÓï¾äÖ´ÐÐËùÓõÄʱ¼ä£¬À´ºâÁ¿SQLÓï¾äµÄÐÔÄÜ¡£
set statistics profile on
set statistics io on
set statistics time on
go
ÄãÖ´ÐеÄSQLÓï¾ä
go
set statistics profile off
set statistics io off
set statistics time off
Ö´ÐÐÍêºóµãÏûÏ¢¼´¿É¡£
²¹³ä˵Ã÷£º
set statistics io ¼ì²é²éѯËù²úÉúµÄ¶ÁºÍд
set statistics time ¼ì²é²éѯµÄÔËÐÐʱ¼ä
µ±ÔËÐÐÒ»sqlÓï¾ä£¬ÔÚÏûÏ¢ÖлáÏÔʾÈ磺
SQL Server ·ÖÎöºÍ±àÒëʱ¼ä:
CPU ʱ¼ä = 0 ºÁÃ룬ռÓÃʱ¼ä = 10 ºÁÃë¡£
SQL Server ·ÖÎöºÍ±àÒëʱ¼ä:
CPU ʱ¼ä = 0 ºÁÃ룬ռÓÃʱ¼ä = 1 ºÁÃë¡£
(0 ÐÐÊÜÓ°Ïì)
±í ‘t_login_session’¡£É¨Ãè¼ÆÊý 1£¬Âß¼¶ÁÈ¡ 2 ´Î£¬ÎïÀí¶ÁÈ¡ 0 ´Î£¬Ô¤¶Á 0 ´Î£¬lob Âß¼¶ÁÈ¡ 0 ´Î£¬lob ÎïÀí¶ÁÈ¡ 0 ´Î£¬lob Ô¤¶Á 0 ´Î¡£
(3 ÐÐÊÜÓ°Ïì)
SQL Server Ö´ÐÐʱ¼ä:
CPU ʱ¼ä = 0 ºÁÃ룬ռÓÃʱ¼ä = 11 ºÁÃë¡£
SQL Server ·ÖÎöºÍ±àÒëʱ¼ä:
CPU ʱ¼ä = 0 ºÁÃ룬ռÓÃʱ¼ä = 1 ºÁÃë¡£
SQL Server Ö´ÐÐʱ¼ä:
CPU ʱ¼ä = 0 ºÁÃ룬ռÓÃʱ¼ä = 1 ºÁÃë¡£
SQL Server Ö´ÐÐʱ¼ä:
CPU ʱ¼ä = 0 ºÁÃ룬ռÓÃʱ¼ä = 1 ºÁÃë¡£
±í ‘t_login_session’¡£É¨Ãè¼ÆÊý 1£¬Âß¼¶ÁÈ¡ 2 ´Î£¬ÎïÀí¶ÁÈ¡ 0 ´Î£¬Ô¤¶Á 0 ´Î£¬lob Âß¼¶ÁÈ¡ 0 ´Î£¬lob ÎïÀí¶ÁÈ¡ 0 ´Î£¬lob Ô¤¶Á 0 ´Î¡£
Õâ¸öɨÃèͳ¼Æ¸æËßÎÒÃÇɨÃèÖ´ÐеÄÊýÁ¿£¬Âß¼¶ÁÏÔʾµÄÊÇ´Ó»º´æÖжÁ³öÀ´µÄÒ³ÃæµÄÊýÁ¿£¬ÎïÀí¶ÁÏÔʾµÄÊÇ´Ó´ÅÅÌÖжÁµÄÒ³ÃæµÄÊýÁ¿£¬Ô¤¶ÁÏÔʾÁË·ÅÖÃÔÚ»º´æÖÐÓÃÓÚ½«À´¶Á²Ù×÷µÄÒ³ÃæÊýÁ¿¡£
ͨ¹ý¿´ÕâЩÐÅÏ¢ÎÒÃÇÄܵõ½Ð©Ê²Ã´ÄØ£¿
¡ôÕâ¸ö²éѯûÓÐɨÃèÕû¸ö±
Ïà¹ØÎĵµ£º
½ñÌìÔÚÓÃUNION½øÐн«Á½¸ö²éѯ½áºÏʱ£¬·¢ÏÖ¼ÓÁËtextÀàÐ͵Ä×ֶνøÈ¥¾Í±¨´íÁË£¬´íÎóÐÅÏ¢ÈçÏ£º
²»ÄÜÒÔ DISTINCT ·½Ê½Ñ¡Ôñ text¡¢ntext »ò image Êý¾ÝÀàÐÍ¡£
¾¹ý·ÔÄ×ÊÁϺó²ÅÖªµÀ£¬ÔÒòÔÚÓÚÈç´Ë²Ù×÷ ÎÞ·¨¶ÔtextÀàÐÍÅжÏÊÇ·ñÖظ´£¬ËùÒÔÒªÔÚUNIONºó¼Ó¸öALL¹Ø¼ü×Ö£¬ÈçÏ£º
select top ......
1¡¢join
A±íµÄÖ÷¼üÊÇ×÷ΪB±íµÄÍâ¼ü¡£ÔÚ²éѯµÄʱºò£¬¿ÉÒÔͨ¹ý²»Í¬µÄjoin½«AºÍB±íÁ´½ÓÆðÀ´£¬´Ó¶øµÃµ½²»Í¬µÄ²éѯ½á¹û¡£
* JOIN: Èç¹û±íÖÐÓÐÖÁÉÙÒ»¸öÆ¥Å䣬Ôò·µ»ØÐÐ
* INNER JOIN: Èç¹ûÁ½¸ö±íÖÐÓÐÆ¥ÅäµÄ£¬Ôò·µ»ØÐÐ
* LEFT JOIN: ¼´Ê¹ÓÒ±íÖÐûÓÐÆ¥Å䣬Ҳ´Ó×ó± ......
SQL like×Ó¾äµÄÁíÒ»ÖÖʵÏÖ·½·¨,ËٶȱÈlike¿ì(ת)
Ò»°ãÀ´ËµÊ¹ÓÃÄ£ºý²éѯ£¬´ó¼Ò¶¼»áÏëµ½LIKE
select * from table where a like '%×Ö·û%'
Èç¹ûÒ»¸öSQLÓï¾äÖÐÓöà¸ö likeÄ£ºý²éѯ£¬²¢ÇҼǼÌõÊýºÜ´ó£¬ÄÇËÙ¶ÈÒ»¶¨»áºÜÂý¡£
ÏÂÃæÁ½ÖÖ·½·¨Ò²¿ÉʵÏÖÄ£ºý²éѯ£º
select * from table where patindex('%×Ö·û%',a)>0 ......
ÔÚ¹¤×÷ÖÐÓöµ½Ò»¸öÎÊÌâ,ÊÇÐèÒªsqlµÝ¹é²éѯµÄ.²»¶®,ÓÚÊǵ½csdnÉÏÈ¥ÎÊ,ÄÇÀïµÄЧÂÊÕæÊǷdz£¸ß,ÎÒÒÔǰҲûÔÚÉÏÃæÎʹýÎÊÌâ.
ÎÊÌâÃèÊö:
ÎÒÓÐÒ»¸ö±í½á¹¹ÈçÏÂ:
id upperid
1 2
3 2
4 1
5 3
¾ßÌå²ã´Î²»ÖªµÀ,ÎÒÏëÓõݹésqlÓ ......