Posted On June 6, 2019

MS SQL: Archive and Shrink Database

kimconnect 0 comments
blog.KimConnect.com >> Database >> MS SQL: Archive and Shrink Database
--Archive Database: with maximum allowed runtime and a set number of records
declare @EndDate datetime, @Recs INT, @maxrunTimeInMinutes INT
SET @maxrunTimeInMinutes = 60
SET @Records = 20000
set @EndDate = dateadd(dd,1,cast(convert(char(10),(select min(logdate) FROM KIMCONNECT.dbo.au_commontable),121) as datetime))
execute [dbo].[pOrccArchive] @maxrunTimeInMinutes = @maxrunTimeInMinutes, @Records = @Records, @EndDate = @EndDate

--Shrink Database:
EXEC pShrinkDatabase 1, 'KIMCONNECT'

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

PowerShell: Get SQL Job History

$computername='sql01' function getSqlJobHistory($sqlServerName){ try{ if(!(get-module SqlServer)){ Install-Module -Name SqlServer } Import-Module -Name SqlServer $sqlServerInstance=Get-SqlInstance -ServerInstance…

SQL: Microsoft Dynamics – Rebuilding a Database View Named ‘FilteredContact’

Why? Update: currently, I'm unable to rebuild this complex view due to SQL constraints. Hence,…

SQL Failover (Simple Method)

$servers="SQL01","SQL02","SQL03"; # Dynamic Credential method 1 $who = whoami if ($who.substring($who.length-2, 2) -eq "-admin"){$username=$who;} else…