我正在尝试使用 the undocumented system procedure sp_MSforeachtable 。但我需要将受影响的表限制为以“smp”开头且位于“dbo”模式中的表。我能够找到如何找到以“smp”开头的程序。我只是这样做:

sp_MSforeachtable @command1=' print ''?''', @whereand=' and name like ''smp%''  '

但是如何使用 @whereand 参数过滤给定模式?

更新 :我尝试了以下操作,但没有用:
sp_MSforeachtable @command1=' print ''?''', @whereand=' and name like ''smp%'' and Left(''?'', 5)=''[dbo]'' '

更新 2 :我在 SQL Server 2000 上运行。

最佳答案

SQL2000 更新:

declare @s nvarchar(1000)
set @s = ' and uid = ' + convert(nvarchar, user_id('my_schema'))
exec sp_msforeachtable @command1='print ''?''', @whereand = @s

关于sql-server - 未记录的系统过程 'sp_MSforeachtable' 和 @whereand 参数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/977400/

10-10 06:10