清除日志的sql

SET NOCOUNT ON

DECLARE @LogicalFileName sysname,

@MaxMinutes INT,

@NewSize INT

?

?

USE cms -- 要操作的數據庫名

SELECT @LogicalFileName = 'cms_log', -- 日志文件名

@MaxMinutes = 10, -- Limit on time allowed to wrap log.

@NewSize = 100 -- 你想設定的日志文件的大小(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

轉載于:https://www.cnblogs.com/jinweijie/archive/2007/05/10/741202.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/391828.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/391828.shtml
英文地址,請注明出處:http://en.pswp.cn/news/391828.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

r語言怎么以第二列繪制線圖_用衛星圖像繪制世界海岸線圖-第二部分

r語言怎么以第二列繪制線圖Part I of this blog series is here.本博客系列的第一部分 在這里 。 At the UKHO we are interested in the oceans, the seabed and the coastline — not to mention everything in and on them! In our previous blog, we (the UKHO Data Scien…

javascript創建類_如何在10分鐘內使用JavaScript創建費用管理器

javascript創建類by Per Harald Borgen通過Per Harald Borgen 如何在10分鐘內使用JavaScript創建費用管理器 (How to create an expense organizer with JavaScript in 10 minutes) 讓我們使用ES6和Dropbox API來防止收據變得混亂。 (Let’s use ES6 and the Dropbox API to k…

豆瓣API

Api V2 索引 圖書Api V2 電影Api V2 音樂Api V2 同城Api V2 廣播Api V2 用戶Api V2 日記Api V2 相冊Api V2 線上活動Api V2 論壇Api V2 回復Api V2 我去Api V2 https://developers.douban.com/wiki/?titleapi_v2 搜索圖書 GET https://api.douban.com/v2/book/search參數意義…

leetcode 485. 最大連續1的個數

給定一個二進制數組&#xff0c; 計算其中最大連續1的個數。 示例 1: 輸入: [1,1,0,1,1,1] 輸出: 3 解釋: 開頭的兩位和最后的三位都是連續1&#xff0c;所以最大連續1的個數是 3. 解題思路 遇到0時&#xff0c;將連續1的長度歸零。遇到1時&#xff0c;累加進長度 代碼 c…

HDU Today

經過錦囊相助&#xff0c;海東集團終于度過了危機&#xff0c;從此&#xff0c;HDU的發展就一直順風順水&#xff0c;到了2050年&#xff0c;集團已經相當規模了&#xff0c;據說進入了錢江肉絲經濟開發區500強。這時候&#xff0c;XHD夫婦也退居了二線&#xff0c;并在風景秀美…

JSP基礎--動作標簽

JSP基礎--動作標簽 JSP動作標簽 1 JSP動作標簽概述 動作標簽的作用是用來簡化Java腳本的&#xff01; JSP動作標簽是JavaWeb內置的動作標簽&#xff0c;它們是已經定義好的動作標簽&#xff0c;我們可以拿來直接使用。 如果JSP動作標簽不夠用時&#xff0c;還可以使用自定義標…

整數存儲怎么轉化為浮點數_非整數值如何存儲在浮點數中(以及為什么要浮點數)...

整數存儲怎么轉化為浮點數by Shukant Pal通過Shukant Pal 非整數值如何存儲在浮點數中(以及為什么要浮點數) (How non-integer values are stored in a float (and why it floats)) Did you ever think how computers work on floating-point numbers? I mean — where does …

rcp rapido_Rapido使用數據改善乘車調度

rcp rapidoGiven our last blog post of the series, which can be found here :鑒于我們在該系列中的最后一篇博客文章&#xff0c;可以在這里找到&#xff1a; We thought it would be helpful to explain how we implemented all of the above into an on-ground experimen…

LeetCode 695. Max Area of Island javascript解決方案

題意&#xff1a; 尋找最大島。leetcode.com/problems/ma… 傳入&#xff1a; [[0,0,1,0,0,0,0,1,0,0,0,0,0], [0,0,0,0,0,0,0,1,1,1,0,0,0], [0,1,1,0,1,0,0,0,0,0,0,0,0], [0,1,0,0,1,1,0,0,1,0,1,0,0], [0,1,0,0,1,1,0,0,1,1,1,0,0], [0,0,0,0,0,0,0,0,0,0,1,0,0], [0…

Mybatis—代理開發和核心配置文件深入

代理開發方式介紹 采用 Mybatis 的代理開發方式實現 DAO 層的開發&#xff0c;這種方式是我們后面進入企業的主流。 Mapper 接口開發方法只需要程序員編寫Mapper 接口&#xff08;相當于Dao 接口&#xff09;&#xff0c;由Mybatis 框架根據接口定義創建接口的動態代理對象&a…

mysql 位操作支持

mysql 支持位操作。 & 位與 &#xff5c; 位或 例如&#xff1a;update car_ins_fee_entity set change_status(change_status | 1) where id12356轉載于:https://www.cnblogs.com/sign-ptk/p/7278225.html

SSRS:之為用戶“NT AUTHORITY\NETWORK SERVICE”授予的權限不足,無法執行此操作。 (rsAccessDenied)...

錯誤信息&#xff1a;為用戶“NT AUTHORITY\NETWORK SERVICE”授予的權限不足&#xff0c;無法執行此操作。 (rsAccessDenied)如圖&#xff1a;解決方案之檢查順序&#xff1a;1.檢查報表的執行服務帳戶。使用“ Reporting Services 配置管理器”。2.檢查數據庫安全 - 登錄名 中…

javascript函數式_如何以及為什么在現代JavaScript中使用函數式編程

javascript函數式by PALAKOLLU SRI MANIKANTA通過PALAKOLLU SRI MANIKANTA In this article, you will get a deep understanding of functional programming and its benefits.在本文中&#xff0c;您將對函數式編程及其好處有深入的了解。 函數式編程簡介 (Introduction To…

飛機上的氧氣面罩有什么用_第2部分—另一個面罩檢測器……(

飛機上的氧氣面罩有什么用This article is part of a series where I will be documenting my journey on the development of a social distancing feedback system for the blind as part of the OpenCV Spatial Competition. Check out the full series: Part 1, Part 2.本文…

Laravel 5 4 實現前后臺登錄

在官網下載 Laravel 5.4 配置并能在訪問 php artisan make:auth 復制代碼生成后路由文件 routes/web.php ,自動有 Auth::routes();Route::get(/home, HomeControllerindex); 復制代碼運行 php artisan migrate 復制代碼執行命令后會生成 users 表和 password_resets 表&#xf…

leetcode 561. 數組拆分 I(排序)

給定長度為 2n 的整數數組 nums &#xff0c;你的任務是將這些數分成 n 對, 例如 (a1, b1), (a2, b2), …, (an, bn) &#xff0c;使得從 1 到 n 的 min(ai, bi) 總和最大。 返回該 最大總和 。 示例 1&#xff1a; 輸入&#xff1a;nums [1,4,3,2] 輸出&#xff1a;4 解釋…

經典網絡流題目模板(P3376 + P2756 + P3381 : 最大流 + 二分圖匹配 + 最小費用最大流)...

題目來源 P3376 【模板】網絡最大流P2756 飛行員配對方案問題P3381 【模板】最小費用最大流最大流 最大流問題是網絡流的經典類型之一&#xff0c;用處廣泛&#xff0c;個人認為網絡流問題最具特點的操作就是建反向邊&#xff0c;這樣相當于給了反悔的機會&#xff0c;不斷地求…

Tensorflow筆記(基礎): 圖與會話,變量

圖與會話 import tensorflow as tf import os# 取消打印 cpu,gpu選擇等的各種警告 # 設置TF_CPP_MIN_LOG_LEVEL 的等級,1.1.0以后設置2后 只不顯示警告,之前需要設置3,但設置3不利于調試 os.environ[TF_CPP_MIN_LOG_LEVEL] 2 import time# 創建一個常量 op, 產生一個 1x2 矩陣…

css左右布局代碼_如何使用CSS位置來布局網站(帶有示例代碼)

css左右布局代碼Using CSS position to layout elements on your website can be hard to figure out. What’s the difference between absolute, relative, fixed, and sticky? It can get confusing pretty quickly.使用CSS位置來布局網站上的元素可能很困難。 絕對&#x…

redis memcached MongoDB

我們現在使用的模式是&#xff0c;對于直接的key value對需緩存的直接用memcached。對于collection類型就使用Redis。對于大數據量的內容性的東西&#xff0c;我們打算嘗試用mongoDB。也正在學習neo4j&#xff0c;來應對深度搜索&#xff0c;推薦功能。 1.Memcached單個key-val…