一 sql中列出的个最小日志记录操作:
SELECT INTO
大容量装载操作(bcp 和 BULK INSERT)
CREATE INDEX(包括索引视图)
text 和 image 操作(WRITETEXT 和 UPDATETEXT)
二 三种恢复模型对这些操作记录日志情况比较
1 简单恢复模型
use master
go
create database test
on ( name='test',
filename='f:/test.mdf',
size=5MB)
log on
( name='test_log',
filename='f:/test_log.ldf',
size=3MB)
go
use test
go
alter database test set recovery simple
select top 10000 a .* into testtable from master..sysobjects a , master..syscolumns b
select count(*) from ::fn_dblog(null,null)
--一个未公开的table-valued funtion 可以看日志文件的记录数
--result :406
dbcc sqlperf(logspace)
--
--Databasename LogSize(MB) Log Space Used(%)
--test 2.9921875 12.5
use master
go
drop database test
2 大容量日志记录恢复模型
这些大容量复制操作的数据丢失程度要比完全恢复模型严重,
不允许恢复部分的BULK操作,只能全部恢复
use master
go
create database test
on ( name='test',
filename='f:/test.mdf',
size=5MB)
log on
( name='test_log',
filename='f:/test_log.ldf',
size=3MB)
go
use test
go
alter database test set recovery BULK_LOGGED
select top 10000 a .* into testtable from master..sysobjects a , master..syscolumns b
select count(*) from ::fn_dblog(null,null)
--result :422
dbcc sqlperf(logspace)
--
--Databasename LogSize(MB) Log Space Used(%)
--test 2.9921875 12.548956
use master
go
drop database test
3 完全恢复模型
记录的日志数要比大容量日志记录恢复模型多,
将记录每一条BCP or BULK insert,create index 的每一条index row,
对image,text字段 WRITETEXT or UPDATETEXT的所有操作
use master
go
create database test
on ( name='test',
filename='f:/test.mdf',
size=5MB)
log on
( name='test_log',
filename='f:/test_log.ldf',
size=3MB)
go
use test
go
alter database test set recovery full
select top 10000 a .* into testtable from master..sysobjects a , master..syscolumns b
select count(*) from ::fn_dblog(null,null)
--result: 582
dbcc sqlperf(logspace)
--
--Databasename LogSize(MB) Log Space Used(%)
--test 2.9921875 57.996082
三 总结
以上语句在不同模式下的比较
FULL模式 BULK_LOGGED 模式
速度 慢 快
日志大小 大 小