日期:2014-05-18  浏览次数:20484 次

查询数据库符合要求的表
查询数据库中满足表记录数大于10000的所有表


查询的结果是满足要求的表 不是select * from tablename

------解决方案--------------------
SQL code

DECLARE @sql NVARCHAR(max)
SET @sql=' DECLARE @table TABLE(table_name VARCHAR(100),cnt INT) 
INSERT INTO @table '
SELECT @sql=@sql+N' SELECT TABLE_NAME='''+TABLE_SCHEMA+N'.'+TABLE_NAME+''',COUNT(1) as cnt FROM '+TABLE_SCHEMA+N'.'+TABLE_NAME+N' union all' 
FROM INFORMATION_SCHEMA.tables
WHERE TABLE_TYPE='BASE TABLE' 
SET @sql=LEFT(@sql,LEN(@sql)-LEN('union all'))
SET @sql=@sql+N'select * from @table where cnt> 10000 '
EXEC(@sql)

------解决方案--------------------
SQL code

SELECT OBJECT_NAME(Id) FROM sysindexes
WHERE indid < 2 AND rows > 10000