declare @s varchar(8000) set @s='' select @s=@s+'select '''+name+''' as TableName, count(*) as Rows from '+name+' union ' from (select name from sysobjects where xtype='U')b group by name set @s=left(@s,len(@s)-6) exec (@s)--如果表太多会出问题
這樣好像可以吧 declare @t_name varchar(50) select distinct [name] from sysobjects where [id] in (select [ID] from syscolumns where [name] in (select [name] from syscolumns where [ID] in (select [ID] from sysobjects where xtype='U' and [name]=@t_name)))
select name,rowcnt from sysindexes where OBJECTPROPERTY(object_id(name), N'IsUserTable') = 1
因为我不知道会影响到那个表,如:
表名 记录数
table1 10000
table2 100002
. .
. .
. .
set @s=''
select @s=@s+'select '''+name+''' as TableName, count(*) as Rows from '+name+' union ' from (select name from sysobjects where xtype='U')b group by name
set @s=left(@s,len(@s)-6)
exec (@s)--如果表太多会出问题
你的方法我测试了,但现在最头痛的是数据库中要近300多张表,我还是没办法解决啊,我知道这个办法很笨,各位高手能否指导一下:如何知道在操作某个表时会影响到其他的表
declare @t_name varchar(50)
select distinct [name] from sysobjects where [id] in
(select [ID] from syscolumns where [name] in
(select [name] from syscolumns where [ID] in
(select [ID] from sysobjects where xtype='U' and [name]=@t_name)))