清空数据日志[转]
全部删除:
1
dump transaction master with no_log;
2
dump transaction master with truncate_only
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
单个删除:
1
DUMP TRANSACTION @DataBaseName WITH NO_LOG
2
DBCC SHRINKFILE( @LogoFileName,@NewSize) --收缩 日志
3
declare @dbname varchar(20)
4
set @dbname='THSYBSecondTest'
5![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
6
--1.清空日志
7
exec('DUMP TRANSACTION ['+@dbname+'] WITH NO_LOG')
8![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
9
--2.截断事务日志:
10
exec('BACKUP LOG ['+@dbname+'] WITH NO_LOG')
11![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
12
--3.收缩数据库文件(如果不压缩,数据库的文件不会减小
13
exec('DBCC SHRINKDATABASE(['+@dbname+'])')
14![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
15
--4.设置自动收缩
16
exec('EXEC sp_dboption '''+@dbname+''',''autoshrink'',''TRUE''')
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
3
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
4
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
5
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
6
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
7
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
8
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
9
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
10
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
11
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
12
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
13
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
14
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
15
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
16
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)