sqlserver sp_msforeachtable用法
? 1、???? 输出当前的用户所有的表 ? ? ???? 2、??? 查询数据所有的表和表中的记录数 ?? sp_msforeachtable ? ? 3、?? 数据库所有表中的ABC列,换成123 ? exec?? sp_msforeachtable?? @command1=N'?? exec(N''update?? ''+@tbname+''?? set?? ''+@s)?? ? ? 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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |