数据库收缩(

时间:2020-12-15 20:47:15
use  [master]         -----------修改master为你的数据库


DECLARE @dbname VARCHAR(60)
SELECT @dbname = CONVERT(VARCHAR(60), DB_NAME())
exec('DUMP TRANSACTION ['+@dbname+'] WITH NO_LOG')
DECLARE @logname VARCHAR(60)
SELECT @logname = rtrim(ltrim(name))
FROM sysfiles
WHERE name LIKE '%log%'
exec('BACKUP LOG ['+@dbname+'] WITH NO_LOG')
exec ('DBCC SHRINKFILE(['+@logname+'],1)')