sql2005怎么还原数据库,和清除垃圾日志文件
发布网友
发布时间:2022-04-13 07:29
我来回答
共1个回答
热心网友
时间:2022-04-13 08:58
ALTER PROCEDURE [dbo].[backupdbname]
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
declare @sql as nvarchar(4000)
set @Sql='del D:\dbname.bak'
exec master..xp_cmdshell @Sql ,no_output
backup database dbname to disk='D:\dbname.bak'
set @Sql='schtasks /run /TN "senddbname"'
--exec master..xp_cmdshell @Sql ,no_output
END
以上是备份的存储过程
RESTORE DATABASE [dbname] FROM DISK = N'D:\dbname.bak' WITH FILE = 1, NOUNLOAD, STATS = 10
以上是还原的sql语句
BACKUP LOG dbname WITH NO_LOG
DUMP TRANSACTION dbname WITH NO_LOG
dbcc shrinkfile (dbname_Log,500)
以上是收缩数据库的语句
如果数据库正在使用中,且文件比较大,收缩不一定很有用
可以备份一下,日志文件会自动清理掉