SQLÊý¾Ý¿âÈÕÖ¾Çå³ýµÄÁ½¸ö·½·¨_SQL SERVERÊý¾Ý¿â_ºÚ¿Í·ÀÏßÍø°²·þÎñÆ÷ά»¤»ùµØ--Powered by WWW.RONGSEN.COM.CN

SQLÊý¾Ý¿âÈÕÖ¾Çå³ýµÄÁ½¸ö·½·¨

×÷ÕߣººÚ¿Í·ÀÏßÍø°²SQLά»¤»ùµØ À´Ô´£ººÚ¿Í·ÀÏßÍø°²SQLά»¤»ùµØ ä¯ÀÀ´ÎÊý£º0

±¾Æª¹Ø¼ü´Ê£º·½·¨Á½¸öÇå³ý
ºÚ¿Í·ÀÏßÍø°²ÍøѶ£ºSQL ServerÊý¾Ý¿âÈÕÖ¾Çå³ýµÄÁ½¸ö·½·¨£º·½·¨Ò»Ò»°ãÇé¿öÏ£¬SQLÊý¾Ý¿âµÄÊÕËõ²¢²»Äܴܺó³Ì¶ÈÉϼõСÊý¾Ý¿â´óС£¬ÆäÖ÷Òª×÷ÓÃÊÇÊÕËõÈÕÖ¾´óС£¬Ó¦µ±¶¨ÆÚ½øÐд˲Ù×÷ÒÔÃâÊý¾Ý¿âÈÕÖ¾¹ý´ó 1¡¢ÉèÖÃÊý¾Ý¿â...

SQL ServerÊý¾Ý¿âÈÕÖ¾Çå³ýµÄÁ½¸ö·½·¨£º

·½·¨Ò»

Ò»°ãÇé¿öÏ£¬SQLÊý¾Ý¿âµÄÊÕËõ²¢²»Äܴܺó³Ì¶ÈÉϼõСÊý¾Ý¿â´óС£¬ÆäÖ÷Òª×÷ÓÃÊÇÊÕËõÈÕÖ¾´óС£¬Ó¦µ±¶¨ÆÚ½øÐд˲Ù×÷ÒÔÃâÊý¾Ý¿âÈÕÖ¾¹ý´ó

1¡¢ÉèÖÃÊý¾Ý¿âģʽΪ¼òµ¥Ä£Ê½£º´ò¿ªSQLÆóÒµ¹ÜÀíÆ÷£¬ÔÚ¿ØÖÆ̨¸ùĿ¼ÖÐÒÀ´Îµã¿ªmicrosoft SQL Server-->SQL Server×é-->Ë«»÷´ò¿ªÄãµÄ·þÎñÆ÷-->Ë«»÷´ò¿ªÊý¾Ý¿âĿ¼-->Ñ¡ÔñÄãµÄÊý¾Ý¿âÃû³Æ£¨ÈçÂÛ̳Êý¾Ý¿âforum£©-->È»ºóµã»÷ÓÒ¼üÑ¡ÔñÊôÐÔ-->Ñ¡ÔñÑ¡Ïî-->ÔÚ¹ÊÕÏ»¹Ô­µÄģʽÖÐÑ¡Ôñ¡°¼òµ¥¡±£¬È»ºó°´È·¶¨±£´æ

2¡¢ÔÚµ±Ç°Êý¾Ý¿âÉϵãÓÒ¼ü£¬¿´ËùÓÐÈÎÎñÖеÄÊÕËõÊý¾Ý¿â£¬Ò»°ãÀïÃæµÄĬÈÏÉèÖò»Óõ÷Õû£¬Ö±½ÓµãÈ·¶¨

3¡¢ÊÕËõÊý¾Ý¿âÍê³Éºó£¬½¨Ò齫ÄúµÄÊý¾Ý¿âÊôÐÔÖØÐÂÉèÖÃΪ±ê׼ģʽ£¬²Ù×÷·½·¨Í¬µÚÒ»µã£¬ÒòΪÈÕÖ¾ÔÚһЩÒì³£Çé¿öÏÂÍùÍùÊǻָ´Êý¾Ý¿âµÄÖØÒªÒÀ¾Ý¡£

·½·¨¶þ

set nocount on
declare @logicalfilename sysname,
        @maxminutes int,
        @newsize int
use     tablename            
-- Òª²Ù×÷µÄÊý¾Ý¿âÃû
select  @logicalfilename = 'tablename_log', 
-- ÈÕÖ¾ÎļþÃû
@maxminutes = 10,              
-- limit on time allowed to wrap log.
        @newsize = 1                 
-- ÄãÏëÉ趨µÄÈÕÖ¾ÎļþµÄ´óС(m)
-- setup / initialize
declare @originalsize int
select @originalsize = size
  from sysfiles
  where name = @logicalfilename
select 'original size of ' + db_name() + ' log is ' +
        convert(varchar(30),@originalsize) + ' 8k pages or ' +
        convert(varchar(30),(@originalsize*8/1024)) + 'mb'
  from sysfiles
  where name = @logicalfilename
create table dummytrans
  (dummycolumn char (8000) not null)
declare @counter   int,
        @starttime datetime,
        @trunclog  varchar(255)
select  @starttime = getdate(),
        @trunclog = 'backup log '
 + db_name() + ' with truncate_only'

dbcc shrinkfile (@logicalfilename, @newsize)
exec (@trunclog)
-- wrap the log if necessary.
while     @maxminutes > datediff
(mi, @starttime, getdate()) -- time has not expired
      and @originalsize =
(select size from sysfiles where name = @logicalfilename) 
      and (@originalsize * 8 /1024) > @newsize 
  begin -- outer loop.
    select @counter = 0
    while  ((@counter < @originalsize / 16) and (@counter < 50000))
      begin -- update
        insert dummytrans values ('fill log') 
        delete dummytrans
        select @counter = @counter + 1
      end  
    exec (@trunclog) 
  end  
select 'final size of ' + db_name() + ' log is ' +
        convert(varchar(30),size) + ' 8k pages or ' +
        convert(varchar(30),(size*8/1024)) + 'mb'
  from sysfiles
  where name = @logicalfilename
drop table dummytrans
set nocount off

    ºÚ¿Í·ÀÏßÍø°²·þÎñÆ÷ά»¤·½°¸±¾ÆªÁ¬½Ó£ºhttp://www.rongsen.com.cn/show-10101-1.html
Íøվά»¤½Ì³Ì¸üÐÂʱ¼ä:2012-03-21 02:29:54  ¡¾´òÓ¡´ËÒ³¡¿  ¡¾¹Ø±Õ¡¿
ÎÒÒªÉêÇë±¾Õ¾£ºNµã | ºÚ¿Í·ÀÏß¹ÙÍø |  
רҵ·þÎñÆ÷ά»¤¼°Íøվά»¤ÊÖ¹¤°²È«´î½¨»·¾³£¬ÍøÕ¾°²È«¼Ó¹Ì·þÎñ¡£ºÚ¿Í·ÀÏßÍø°²·þÎñÆ÷ά»¤»ùµØÕÐÉ̽øÐÐÖУ¡QQ:29769479

footer  footer  footer  footer