我正在下面在执行语句时的错误:EXEC master.sys.sp_MSforeachdb错误
EXEC master.sys.sp_MSforeachdb
'INSERT INTO AuditDatabase.dbo.[DataDictionary]
exec sp_get_extendedproperty "?"'
:
EXEC master.sys.sp_MSforeachdb
'INSERT INTO AuditDatabase.dbo.[DataDictionary]
exec sp_get_extendedproperty use [?] "?"'
Msg 102, Level 15, State 1, Line 23
Incorrect syntax near 'master'.
Msg 102, Level 15, State 1, Line 23
Incorrect syntax near 'tempdb'.
Msg 102, Level 15, State 1, Line 23
Incorrect syntax near 'model'.
Msg 102, Level 15, State 1, Line 23
Incorrect syntax near 'msdb'.
Msg 102, Level 15, State 1, Line 23
Incorrect syntax near 'AdventureWorks2014'.
Msg 102, Level 15, State 1, Line 23
Incorrect syntax near 'TestDatabase'.
Msg 102, Level 15, State 1, Line 23
Incorrect syntax near 'AuditDatabase'.
如果我不使用语法像这样运行
它只循环通过AdventureWorks2014和msdb数据库。它不通过任何其他数据库循环。
sp_get_extendedproperty在master db上。
注意:'sp_MSforeachdb'是臭名昭着的不可靠的。请参阅:http://sqlblog.com/blogs/aaron_bertrand/archive/2010/12/29/a-more-reliable-and-more-flexible-sp-msforeachdb.aspx – 2015-04-03 18:28:05