首页 > 数据库技术 > 详细

Mysql和Sql查询表信息

时间:2021-09-11 13:45:01      阅读:25      评论:0      收藏:0      [点我收藏+]

 

 

Mysql

SELECT TABLE_NAME,TABLE_ROWS,DATA_LENGTH/1024/1024 "DATA_LENGTH",CREATE_TIME,TABLE_COLLATION 
FROM
INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = ‘数据库名称‘ ORDER BY TABLE_ROWS DESC

  

Sql

IF OBJECT_ID(‘tempdb..#TablesSizes‘) IS NOT NULL

    DROP TABLE #TablesSizes

CREATE TABLE #TablesSizes

    (

      TableName sysname ,

      Rows BIGINT ,

      reserved VARCHAR(100) ,

      data VARCHAR(100) ,

      index_size VARCHAR(100) ,

      unused VARCHAR(100)

    )

DECLARE @sql VARCHAR(MAX)

SELECT  @sql = COALESCE(@sql, ‘‘) + ‘

INSERT INTO #TablesSizes execute sp_spaceused ‘‘‘ + QUOTENAME(TABLE_SCHEMA,

                                                              ‘[]‘) + ‘.‘

        + QUOTENAME(Table_Name, ‘[]‘) + ‘‘‘‘

FROM    INFORMATION_SCHEMA.TABLES

WHERE   TABLE_TYPE = ‘BASE TABLE‘

PRINT ( @SQL )

EXECUTE (@SQL)

SELECT  *

FROM    #TablesSizes

ORDER BY Rows DESC

  

  

Mysql和Sql查询表信息

原文:https://www.cnblogs.com/lhlong/p/15247197.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!