Compressed SQL Server database

xiaoxiao2021-03-06  46

If the log file (LDF) of the database is found is too powerful, the following two steps can be taken:

(1) Change the Recovery Model to Simple (default is FULL)

(2) Run the DBCC SHRINKDATABASE command to compress the database

Function code:

Public Shared Function ShrinkDatabase (Byval dbconnection as sqlclient.sqlconnection, byval dbname as string) as boolean

'Set the recovery mode to Simple and the shrink the database

DIM SSQL AS String

SSQL = "ALTER DATABASE [" & DBNAME & "] Set Recovery SIMPLE"

DIM SQLCMD As New Sqlclient.sqlcommand (SSQL, DBConnection)

Sqlcmd.executenonQuery ()

SSQL = "DBCC ShrinkDatabase (N '" & DBNAME & "', TRUNCATEONLY"

Sqlcmd.commandtext = SSQL

Sqlcmd.executenonQuery ()

END FUNCTION

转载请注明原文地址:https://www.9cbs.com/read-80628.html

New Post(0)