赞
踩
Parameters
Type
sp_Msforeachtable
sp_Msforeachdb
Description
@precommand
nvarchar(2000)
Yes
Yes
This command is executed before any commands and can be used for setting up an environment for commands execution.
@command1
nvarchar(2000)
Yes
Yes
First command to be executed against each table/database.
@command2
nvarchar(2000)
Yes
Yes
Second command to be executed against each table/database.
@command3
nvarchar(2000)
Yes
Yes
Third command to be executed against each table/database.
@postcommand
nvarchar(2000)
Yes
Yes
This command is executed after any other commands and can be used for cleanup process after commands execution.
@replacechar
nchar(1)
Yes
Yes
Default value is “?” which represents the database/table name. You may need to change this value if you want “?” mark to be used in your query.
@whereand
nvarchar(2000)
Yes
No
With this you can specify the filtering criteria for your table collection. For details see the script section,
脚本1演示了sp_MSForEachTable的用法。第1条语句列出当前库所有的表和总的记录数,而语句2输出当前库下各表的空间占用情况。(注:在@cmd里用’’表示单引号,如select ‘’?’’)
Script #1 : sp_MSForEachTable system stored procedure
–List all the tables of current database and total no rows in it
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。