SQL ServerÖд洢¹ý³Ì±ÈÖ±½ÓÔËÐÐSQLÓï¾äÂýµÄÔÒò
ÔںܶàµÄ×ÊÁÏÖж¼ÃèÊö˵SQLSERVERµÄ´æ´¢¹ý³Ì½ÏÆÕͨµÄSQLÓï¾äÓÐÒÔÏÂÓŵ㣺
1. ´æ´¢¹ý³ÌÖ»ÔÚ´´Ôìʱ½øÐбàÒë¼´¿É£¬ÒÔºóÿ´ÎÖ´Ðд洢¹ý³Ì¶¼²»ÐèÔÙÖØбàÒ룬¶øÎÒÃÇͨ³£Ê¹ÓõÄSQLÓï¾äÿִÐÐÒ»´Î¾Í±àÒëÒ»´Î,ËùÒÔʹÓô洢¹ý³Ì¿ÉÌá¸ßÊý¾Ý¿âÖ´ÐÐËٶȡ£
2. ¾³£»áÓöµ½¸´ÔÓµÄÒµÎñÂß¼ºÍ¶ÔÊý¾Ý¿âµÄ²Ù×÷£¬Õâ¸öʱºò¾Í»áÓÃSPÀ´·â×°Êý¾Ý¿â²Ù×÷¡£µ±¶ÔÊý¾Ý¿â½øÐи´ÔÓ²Ù×÷ʱ(Èç¶Ô¶à¸ö±í½øÐÐ Update,Insert,Query,Deleteʱ£©£¬¿É½«´Ë¸´ÔÓ²Ù×÷Óô洢¹ý³Ì·â×°ÆðÀ´ÓëÊý¾Ý¿âÌṩµÄÊÂÎñ´¦Àí½áºÏÒ»ÆðʹÓ᣿ÉÒÔ¼«´óµÄÌá¸ßÊý¾Ý¿âµÄʹÓÃЧÂÊ£¬¼õÉÙ³ÌÐòµÄÖ´ÐÐʱ¼ä£¬ÕâÒ»µãÔڽϴóÊý¾ÝÁ¿µÄÊý¾Ý¿âµÄ²Ù×÷ÖÐÊǷdz£ÖØÒªµÄ¡£ÔÚ´úÂëÉÏ¿´£¬SQLÓï¾äºÍ³ÌÐò´úÂëÓï¾äµÄ·ÖÀ룬¿ÉÒÔÌá¸ß³ÌÐò´úÂëµÄ¿É¶ÁÐÔ¡£
3. ´æ´¢¹ý³Ì¿ÉÒÔÉèÖòÎÊý£¬¿ÉÒÔ¸ù¾Ý´«Èë²ÎÊýµÄ²»Í¬Öظ´Ê¹ÓÃͬһ¸ö´æ´¢¹ý³Ì£¬´Ó¶ø¸ßЧµÄÌá¸ß´úÂëµÄÓÅ»¯ÂʺͿɶÁÐÔ¡£
4. °²È«ÐÔ¸ß,¿ÉÉ趨ֻÓÐij´ËÓû§²Å¾ßÓжÔÖ¸¶¨´æ´¢¹ý³ÌµÄʹÓÃȨ´æ´¢¹ý³ÌµÄÖÖÀࣺ
A. ϵͳ´æ´¢¹ý³Ì£ºÒÔsp_¿ªÍ·,ÓÃÀ´½øÐÐϵͳµÄ¸÷ÏîÉ趨.È¡µÃÐÅÏ¢.Ïà¹Ø¹ÜÀí¹¤×÷,Èç sp_help¾ÍÊÇÈ¡µÃÖ¸¶¨¶ÔÏóµÄÏà¹ØÐÅÏ¢¡£
B. À©Õ¹´æ´¢¹ý³Ì ÒÔXP_¿ªÍ·,ÓÃÀ´µ÷ÓòÙ×÷ϵͳÌṩµÄ¹¦ÄÜ
exec master..xp_cmdshell 'ping 10.8.16.1'
C. Óû§×Ô¶¨ÒåµÄ´æ´¢¹ý³Ì,ÕâÊÇÎÒÃÇËùÖ¸µÄ´æ´¢¹ý³Ì³£Óøñʽ
Ä£°æ£ºCreate procedure procedue_name [@parameter data_type][output]
[with]{recompile|encryption} as sql_statement
½âÊÍ£ºoutput£º±íʾ´Ë²ÎÊýÊÇ¿É´«»ØµÄ
with {recompile|encryption} recompile:±íʾÿ´ÎÖ´Ðд˴洢¹ý³Ìʱ¶¼ÖØбàÒëÒ»´Î;encryption:Ëù´´½¨µÄ´æ´¢¹ý³ÌµÄÄÚÈݻᱻ¼ÓÃÜ¡£
µ«ÊÇ×î½üÎÒÃÇÏîÄ¿×éÖÐÓÐÈËдÁËÒ»¸ö´æ´¢¹ý³Ì,Æä¼ÆËãʱ¼äΪ1¸öСʱ47·ÖÖÓ,¶øÓеÄʱºòÔËÐÐʱ¼ä¶¼³¬¹ýÁËÁ½¸öСʱ,ͬÊÂÃèÊö˵Èç¹û½«´æ´¢¹ý³ÌÖеÄÓï¾äÄóöÀ´Ö±½ÓÔËÐÐÒ²¾Í10·ÖÖÓ×óÓÒ¾ÍÔËÐÐÍê±Ï£¬ÎÒûµ±»ØÊ£¬µ«ÊǽñÌìÎÒ×Ô¼ºÐ´µÄ´æ´¢¹ý³ÌÒ²Óöµ½ÁËÕâ¸öÎÊÌ⣬ÔÚ²éÕÒ×ÊÁϺóÔÒòÖÕÓÚÕÒµ½ÁËÔÒò£¬ÔÀ´ÊÇParameter sniffingÎÊÌâ¡£
ÏÂÃæ¿´ÎÒÊÇÈçºÎ½«
Ïà¹ØÎĵµ£º
±¾À´ÊÇmssql+hibernate+native SQL Ó¦ÓõĺܺÍг
µ«Êǵ½ÁË°Ñmssql»»³Émysql£¬¾Í³öÁË´í(ͬÑùµÄÊý¾Ý½á¹¹ºÍÊý¾Ý)¡£
²éѯ·½·¨ÊÇ£º
String sql =
"select id XXX_ID from t_tab";
List<Map> list = session.createSQLQuery(sql)
.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP)
.list();
´í ......
SQL Server 2005 (MSSQLSERVER) ·þÎñ²»ÄÜÆô¶¯
ÔÒò:VIAÐÒ锸øÆôÓÃÁË£¬Í£ÓÓVIAÐÒé”ÎÊÌâ½â¾ö¡£
"VIAÐÒé"Í£Ó÷½·¨£º¿ªÊ¼->³ÌÐò->Microsoft SQL Server 2005->ÅäÖù¤¾ß->SQL Server Configuration Manager ->´ò¿ªºóÕÒµ½"SQL Server 2005 ÍøÂçÅäÖÃ"->MSSQLSERVER ÊôÐÔµÄÐÒé &nb ......
1.Union
UNION Ö¸ÁîµÄÄ¿µÄÊǽ«Á½¸ö SQL Óï¾äµÄ½á¹ûºÏ²¢ÆðÀ´¡£´ÓÕâ¸ö½Ç¶ÈÀ´¿´£¬ UNION ¸ú JOIN ÓÐЩÐíÀàËÆ£¬ÒòΪÕâÁ½¸öÖ¸Á¿ÉÒÔÓɶà¸ö±í¸ñÖÐߢȡ×ÊÁÏ¡£ UNION µÄÒ»¸öÏÞÖÆÊÇÁ½¸ö SQL Óï¾äËù²úÉúµÄÀ¸Î»ÐèÒªÊÇͬÑùµÄ×ÊÁÏÖÖÀà¡£ÁíÍ⣬µ±ÎÒÃÇÓà UNIONÕâ¸öÖ¸Áîʱ£¬ÎÒÃÇÖ»»á¿´µ½²»Í¬µÄ×ÊÁÏÖµ (ÀàËÆ SELECT DISTINCT)¡£
UNION µ ......
DECLARE @sql varchar(8000)
--ÏÂÃæÊÇɾ³ý15ÌìÇ°±¸·ÝÎļþµÄ´¦Àí
set @sql='Del E:\Databasebackup\'
@sql=@sql +rtrim(convert(varchar,getdate()-15,112))+'.bak'
Exec master..xp_cmdshell @sql
DECLARE @DelFile Varchar(256)
set ......
1. SET DEADLOCK_PRIORITY
˵Ã÷£º¿ØÖÆÔÚ·¢ÉúËÀËøÇé¿öʱ»á»°µÄ·´Ó¦·½Ê½¡£Èç¹ûÁ½¸ö½ø³Ì¶¼Ëø¶¨Êý¾Ý£¬²¢ÇÒÖ±µ½ÆäËü½ø³ÌÊÍ·Å×Ô¼ºµÄËøʱ£¬Ã¿¸ö½ø³Ì²ÅÄÜÊÍ·Å×Ô¼ºµÄËø£¬¼´·¢ÉúËÀËøÇé¿ö¡£
Óï·¨£ºSET DEADLOCK_PRIORITY { LOW | NORMAL | @deadlock_var }
²ÎÊý£ºLOW Ö¸¶¨µ±Ç°»á»°ÎªÊ×Ñ¡ËÀËøÎþÉüÆ·¡£Microsoft® S ......