我正在下面在執行語句時的錯誤: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