未记录的系统过程“sp_MSforeachtable” 和@whereand参数
我正在尝试使用 未记录的系统过程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 上运行。
I'm attempting to use the undocumented system procedure sp_MSforeachtable
. But I need to restrict the affected tables to those that start with "smp" and that are in the "dbo
" schema. I was able to find how to find procedures that start with "smp". I simply do:
sp_MSforeachtable @command1=' print ''?''', @whereand=' and name like ''smp%'' '
but how do I filter for a given schema using the @whereand
parameter?
UPDATE: I tried the following but it didn't work:
sp_MSforeachtable @command1=' print ''?''', @whereand=' and name like ''smp%'' and Left(''?'', 5)=''[dbo]'' '
Update 2: I'm running on SQL Server 2000.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
SQL2000 的更新:
Update for SQL2000:
这应该适用于 SQL Server 2000(现在无法测试):
使用 OBJECTPROPERTY 查找架构所有者 ID。
编辑:好的,在 SQL 2000 机器上测试了它:
我无法让 OBJECTPROPERTY 工作
This should works in SQL Server 2000 (can't test now):
Use OBJECTPROPERTY to find the schema owner id.
Edit: OK, tested it on a SQL 2000 box:
I could not get OBJECTPROPERTY to work
来自此处:
From here:
此版本适用于 Sql Server 2005:
不太确定是否适用于 Sql Server 2000,但此版本可能适用:
This verion works in Sql Server 2005:
Not exactly sure for Sql Server 2000, but this version might work:
这在 2008 R2 中有效
@whereand='and uid = (SELECT schema_id FROM sys.schemas WHERE name = ''dbo'') and o.name LIKE ''TEMP_%'''
This worked in 2008 R2
@whereand='and uid = (SELECT schema_id FROM sys.schemas WHERE name = ''dbo'') and o.name LIKE ''TEMP_%'''