csjsias

博客园 首页 新随笔 联系 订阅 管理

   DECLARE tables_cursor CURSOR
      FOR
      SELECT top 100 name FROM sysobjects WHERE type = 'U' order by name
   OPEN tables_cursor
   DECLARE @tablename varchar(30), @quote char(1)
   SELECT @quote = ''

   FETCH NEXT FROM tables_cursor INTO @tablename
   WHILE (@@fetch_status <> -1)
   BEGIN
      EXEC ('Select count(*) as ''' + @tablename + ''' from '+  @tablename)
      FETCH NEXT FROM tables_cursor INTO @tablename
   END
   DEALLOCATE tables_cursor

posted on 2011-12-03 08:15  快乐121  阅读(182)  评论(0)    收藏  举报