数据库收缩(<sql2008)

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)')
posted @ 2011-07-26 20:03  qanholas  阅读(211)  评论(0编辑  收藏  举报