zoukankan      html  css  js  c++  java
  • 查询sql server 2008所有表和行数

    查询sql server 2008所有表和行数

    SELECT   a.name, b.rows
    FROM      sysobjects AS a INNER JOIN
                     sysindexes AS b ON a.id = b.id
    WHERE   (a.type = 'u') AND (b.indid IN (0, 1))
    ORDER BY b.rows DESC
    SELECT object_name (i.id) TableName, 
           rows as RowCnt 
    FROM sysindexes i 
    INNER JOIN sysObjects o 
        ON (o.id = i.id AND o.xType = 'U ') 
    WHERE indid < 2 
    ORDER BY TableName 
     
    --****************** 
     
    --two: 使用未公开的过程 "sp_MSforeachtable " 
    CREATE TABLE #temp (TableName VARCHAR (255), RowCnt INT) 
    EXEC sp_MSforeachtable 'INSERT INTO #temp SELECT ''?'', COUNT(*) FROM ?' 
    SELECT TableName, RowCnt FROM #temp ORDER BY TableName 
    DROP TABLE #temp 
     
    --****************** 
     
    -- three: 使用游标.cursor 
    SET NOCOUNT ON 
    DECLARE @tableName VARCHAR (255),
            @sql VARCHAR (300) 
    CREATE TABLE #temp (TableName VARCHAR (255), rowCnt INT) 
    DECLARE myCursor CURSOR FAST_FORWARD READ_ONLY FOR 
        SELECT TABLE_NAME 
        FROM INFORMATION_SCHEMA.TABLES 
        WHERE TABLE_TYPE = 'base table ' 
    OPEN myCursor 
    FETCH NEXT FROM myCursor INTO @tableName 
    WHILE @@FETCH_STATUS = 0 
        BEGIN 
        EXEC ( 'INSERT INTO #temp (TableName, rowCnt) SELECT ''' + @tableName + ''' as tableName, count(*) as rowCnt from ' + @tableName) 
        FETCH NEXT FROM myCursor INTO @tableName 
        END 
    SELECT TableName, RowCnt FROM #temp ORDER BY TableName 
    CLOSE myCursor 
    DEALLOCATE myCursor 
    DROP TABLE #temp
  • 相关阅读:
    关于params
    javascript判断gridview中的checkbox是否选中!
    读取Excel内容,导入数据库多张表!
    转向新页,控制页面大小并传值
    DropDownList分层显示!
    验证输入的是否数字的几种方法
    CentOS 6.5编译安装Nginx1.6.2+MySQL5.5.32+PHP5.3.27
    hdu 2425最短路
    hdu 2207水题
    hdu 3079水题
  • 原文地址:https://www.cnblogs.com/m0488/p/9444365.html
Copyright © 2011-2022 走看看