日期:2014-05-17 浏览次数:20601 次
declare @name varchar(200)
declare A cursor for (SELECT name FROM sysobjects where type='U')
OPEN A
fetch next from A into @name
WHILE @@FETCH_STATUS=0
begin
---这里怎么写呢??
fetch next from A into @name
end
close A
deallocate A
declare @s varchar(200)
set @s =''
declare @t table (tablename varchar(20), ct int)
set @s ='select '+@name+' count(1) from '+@name
insert into @t
exec (@s)
select * from @t
select distinct OBJECT_NAME(id)
from sys.sysindexes
where id > 100 --and indid =0
and rowcnt >0
declare @name varchar(200)
declare @i int
declare @result table (name varchar(100))
declare @s nvarchar(100)
declare A cursor for (SELECT name FROM sysobjects where type='U')
OPEN A
fetch next from A into @name
WHILE @@FETCH_STATUS=0
begin
set @s='select @i=COUNT(1) from '+@name+''
exec sp_executesql @s,N'@i int output',@i output
if @i=0
insert into @result select @name
fetch next from A into @name
end
close A
deallocate A
select * from @result
-----------
name
员工工资表
员工考勤表
员工请假表
Job
na
员工信息表
--也来一个吧
exec sp_MSForEachTable
@precommand=N'
create table ##(
表名 sysname,
记录数 int,
保留空间 Nvarchar(10),
使用空间 varchar(10),