使用sql server2005清空数据库可用以下sql实现 backup log dnname with no_log go dump transaction dnname with no_log go use dnname dbcc shrinkfile (2) go 不过这个存储过程在sql server2008中已经被取消,在2008需要改用以下方式来清空数据库日志 use
使用sql server2005清空数据库可用以下sql实现
backup log dnname with no_log
go
dump transaction dnname with no_log
go
use dnname
dbcc shrinkfile (2)
go
不过这个存储过程在sql server2008中已经被取消,,在2008需要改用以下方式来清空数据库日志
use [master]
go
alter database dnname set recovery simple with no_wait
go
alter database dnname set recovery simple --简单模式
go
use dnname
go
dbcc shrinkfile (n'dnname_log' , 11, truncateonly)
go
use [master]
go
alter database dnname set recovery full with no_wait
go
alter database dnname set recovery full --还原为完全模式
go
另外,在用sql server 2008附加数据库的时候提示文件为只读,附加失败。但是查看文件属性并不是只读。这是由于使用sa登录数据库,只能附加data目录下的文件。需要采用系统用户登录,或将 sql server 服务的帐户登录身份由 network service 改为 local service