sqlserver sp_msforeachtable用法
来源:互联网 发布:w10打开软件防火墙 编辑:程序博客网 时间:2024/05/22 01:41
1、 输出当前的用户所有的表
sp_msforeachtable
@command1="print '?'"
2、 查询数据所有的表和表中的记录数
sp_msforeachtable
@command1="select '?' as 表名,count(*) as 记录数 from ?"
3、 数据库所有表中的ABC列,换成123
exec sp_msforeachtable @command1=N'
declare @s nvarchar(4000),@tbname sysname
select @s=N'''',@tbname=N''?''
select @s=@s+N'',''+quotename(a.name)+N''=replace(''+quotename(a.name)+N'',N''''ABC'''',N''''123'''')''
from syscolumns a,systypes b
where a.id=object_id(@tbname)
and a.xusertype=b.xusertype
and b.name like N''%char''
if @@rowcount>0
begin
set @s=stuff(@s,1,1,N'''')
print(N''update ''+@tbname+'' set ''+@s)
exec(N''update ''+@tbname+'' set ''+@s)
end'
4、查询数据库每个表的空间利用情况
set nocount on
exec sp_MSForEachTable
@precommand=N'
create table ##(
id int identity,
表名 sysname,
字段数 int,
记录数 int,
保留空间 Nvarchar(10),
使用空间 varchar(10),
索引使用空间 varchar(10),
未用空间 varchar(10))',
@command1=N'insert ##(表名,记录数,保留空间,使用空间,索引使用空间,未用空间) exec sp_spaceused ''?''
update ## set 字段数=(select count(*) from syscolumns where id=object_id(''?'')) where id=scope_identity()',
@postcommand=N'select * from ## order by 记录数 desc drop table ##'
set nocount off
- sqlserver sp_msforeachtable用法
- SQLServer sp_MSforeachtable和sp_MSforeachdb用法
- sp_MSforeachtable
- mssql里sp_MSforeachtable和sp_MSforeachdb的用法
- 浅析sp_MSforeachtable和sp_MSforeachdb的用法
- mssql里sp_MSforeachtable和sp_MSforeachdb的用法
- mssql里sp_MSforeachtable和sp_MSforeachdb的用法
- 【推荐】(SqlServer)不公开存储过程sp_Msforeachtable与sp_Msforeachdb详解
- (SqlServer)不公开存储过程sp_Msforeachtable与sp_Msforeachdb详解
- sp_MSforeachtable sp_MSforeachdb
- sp_MSforeachtable使用方法
- sp_MSforeachtable 使用方法
- sp_MSforeachtable使用方法
- sp_MSforeachtable使用方法
- sp_MSforeachtable使用方法
- sp_MSforeachtable使用方法
- sp_MSforeachtable的用法,对某数据库的所有表进行操作
- Sqlserver中游标的用法
- strust2实践总结
- linux一个漏洞的分析
- VC++6.0调试篇:运行时间的观察--watch窗口的技巧续
- mysql 远程登录修改方法
- vim详细手册
- sqlserver sp_msforeachtable用法
- 我的职业观——HP大中华区总裁孙振耀退休感言
- 恋爱婚姻法则与职场规则
- JS设计模式(三)
- Windows DOS命令
- GPRS
- Windows中主流的调试器介绍
- 头文件的包含
- X.25网络