For each db / table

Posted 拂髯客

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了For each db / table相关的知识,希望对你有一定的参考价值。

use master
go
exec master..sp_MSforeachdb ‘use [?]; IF (SELECT db_id(‘‘?‘‘)) > 4 and (SELECT DATABASEPROPERTYEX(‘‘?‘‘, ‘‘Recovery‘‘)) =‘‘FULL‘‘ BACKUP LOG [?] to disk = ‘‘NUL‘‘‘
WAITFOR Delay ‘00:10:00‘
exec master..sp_MSforeachdb ‘use [?]; IF (SELECT db_id(‘‘?‘‘)) > 4 and (SELECT DATABASEPROPERTYEX(‘‘?‘‘, ‘‘Recovery‘‘)) =‘‘FULL‘‘ BACKUP LOG [?] to disk = ‘‘NUL‘‘‘
EXEC master..sp_MSforeachdb ‘use [?]; IF (SELECT db_id(‘‘?‘‘)) > 4 and (SELECT DATABASEPROPERTYEX(‘‘?‘‘, ‘‘Recovery‘‘)) =‘‘FULL‘‘ begin declare @Log varchar(127); select @Log = (select top 1 rtrim(name) from sysfiles where name like ‘‘%log%‘‘); DBCC SHRINKFILE(@Log,32); end‘


ps: 实际上 sp_helptext 时候会发现内部还用到 sp_MSForEachWorker

  

以上是关于For each db / table的主要内容,如果未能解决你的问题,请参考以下文章

MySQL Trigger AFTER INSERT ON 'table name' FOR EACH ROW WHEN (role_id = 3)

js table td读取片段

在 for-each 循环之外保存模型

具有来自 .tfvars 的值的 terraform for_each 实现

Incorrect key file for table './xx_db/xx_table.MYI'; try to repair it

for each 和 for_each 有啥区别?