请问 zjcxc(邹建): "sp_msforeachtable"怎么找不到?

eddiezhuo 2004-08-23 09:49:01
请问 zjcxc(邹建): 你在这个贴子里(http://community.csdn.net/Expert/topic/3287/3287372.xml?temp=.5120966),用到"sp_msforeachtable" 怎么找不到?
...全文
132 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
lynx1111 2004-08-23
  • 打赏
  • 举报
回复
http://dev.csdn.net/develop/article/25/25018.shtm
eddiezhuo 2004-08-23
  • 打赏
  • 举报
回复
谢了,就这个功能吗?
又学了一招.
老宛 2004-08-23
  • 打赏
  • 举报
回复
--sp_msforeachtable,他的内容是:
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


create proc sp_MSforeachtable
@command1 nvarchar(2000), @replacechar nchar(1) = N'?', @command2 nvarchar(2000) = null,
@command3 nvarchar(2000) = null, @whereand nvarchar(2000) = null,
@precommand nvarchar(2000) = null, @postcommand nvarchar(2000) = null
as
/* This proc returns one or more rows for each table (optionally, matching @where), with each table defaulting to its own result set */
/* @precommand and @postcommand may be used to force a single result set via a temp table. */

/* Preprocessor won't replace within quotes so have to use str(). */
declare @mscat nvarchar(12)
select @mscat = ltrim(str(convert(int, 0x0002)))

if (@precommand is not null)
exec(@precommand)

/* Create the select */
exec(N'declare hCForEach cursor global for select ''['' + REPLACE(user_name(uid), N'']'', N'']]'') + '']'' + ''.'' + ''['' + REPLACE(object_name(id), N'']'', N'']]'') + '']'' from dbo.sysobjects o '
+ N' where OBJECTPROPERTY(o.id, N''IsUserTable'') = 1 ' + N' and o.category & ' + @mscat + N' = 0 '
+ @whereand)
declare @retval int
select @retval = @@error
if (@retval = 0)
exec @retval = sp_MSforeach_worker @command1, @replacechar, @command2, @command3

if (@retval = 0 and @postcommand is not null)
exec(@postcommand)

return @retval

GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

pbsql 2004-08-23
  • 打赏
  • 举报
回复
例:
exec sp_msforeachtable 'select * from ?'--对每个表执行select语句,问号代表表名
eddiezhuo 2004-08-23
  • 打赏
  • 举报
回复
知道怎么用了,介绍一下功能吧?
eddiezhuo 2004-08-23
  • 打赏
  • 举报
回复
哪我要怎么用?
pbsql 2004-08-23
  • 打赏
  • 举报
回复
是系统存储过程,该存储过程在帮助里是没有介绍的
zjcxc 元老 2004-08-23
  • 打赏
  • 举报
回复
那个是未公开的存储过程,当然找不到.

34,594

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧