第一种:进去指定schema 数据库(存放了其他的数据库的信息)
use information_schema
第二种:查询所有数据的大小
select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data from TABLES(>
1、进去指定schema 数据库(存放了其他的数据库的信息)\x0d\use information_schema\x0d\2、查询所有数据的大小\x0d\select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data from TABLES\x0d\3、查看指定数据库的大小\x0d\比如说 数据库apoyl\x0d\select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data from TABLES where table_schema='apoyl';\x0d\4、查看指定数据库的表的大小\x0d\比如说 数据库apoyl 中apoyl_test表\x0d\select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data from TABLES where table_schema='apoyl' and table_name='apoyl_test';\x0d\整完了,有兴趣的可以试哈哦!挺使用哈\x0d\网站找的,都是正解
/
--用BCP试试,不行再用下面的存储过程
EXEC masterxp_cmdshell 'bcp "select from testdboApo_village"
queryout "c:/Apo_SFZxlsx" -c -S"服务器" -U"sa" -P"密码"'
/
--这是用C#写的存储过程,不知道你会不会编译到SQL Server
--在数据库这样调用就是了
--Exec BulkCopyToXls 'SQL查询语句','路径','文件名',最大记录数
--Exec BulkCopyToXls 'select from 表','G:\Test','Table',60000
using System;using SystemData;
using SystemDataSqlClient;
using SystemDataSqlTypes;
using MicrosoftSqlServerServer;
public partial class myProcedure
{
[MicrosoftSqlServerServerSqlProcedure]
public static void BulkCopyToXls(SqlString sql, SqlString savePath, SqlString tableName, SqlInt32 maxRecordCount)
{
if (sqlIsNull || savePathIsNull || tableNameIsNull)
{
SqlContextPipeSend(" 输入信息不完整!");
}
//每个excel文件最大容纳65534
ushort _maxRecordCount = ushortMaxValue - 1;
if (maxRecordCountIsNull == false && maxRecordCountValue < ushortMaxValue && maxRecordCountValue > 0)
_maxRecordCount = (ushort)maxRecordCountValue;
ExportXls(sqlValue, savePathValue, tableNameValue, _maxRecordCount);
}
private static void ExportXls(string sql, string savePath, string tableName, SystemUInt16 maxRecordCount)
{
//创建文件路径
if (SystemIODirectoryExists(savePath) == false)
{
SystemIODirectoryCreateDirectory(savePath);
}
using (SqlConnection conn = new SqlConnection("context connection=true"))
{
connOpen();
using (SqlCommand command = connCreateCommand())
{
commandCommandText = sql;
using (SqlDataReader reader = commandExecuteReader())
{
int i = 0;
int totalCount = 0;
int tick = SystemEnvironmentTickCount;
SqlContextPipeSend(" 开始导出数据");
while (true)
{
string fileName = stringFormat(@"{0}/{1}{2}xls", savePath, tableName, i++);
int iExp = Write(reader, maxRecordCount, fileName);
long size = new SystemIOFileInfo(fileName)Length;
totalCount += iExp;
SqlContextPipeSend(stringFormat(" 文件{0}, 共{1} 条, 大小{2} 字节", fileName, iExp, sizeToString("###,###")));
if (iExp < maxRecordCount) break;
}
tick = SystemEnvironmentTickCount - tick;
SqlContextPipeSend(" 导出数据完成");
SqlContextPipeSend("-------");
SqlContextPipeSend(stringFormat(" 共{0} 条数据,耗时{1}ms", totalCount, tick));
}
}
}
} private static void WriteObject(ExcelWriter writer, object obj, SystemUInt16 x, SystemUInt16 y)
{
//判断写数字还是写字符
string type = objGetType()NameToString();
switch (type)
{
case "SqlBoolean":
case "SqlByte":
case "SqlDecimal":
case "SqlDouble":
case "SqlInt16":
case "SqlInt32":
case "SqlInt64":
case "SqlMoney":
case "SqlSingle":
if (objToString()ToLower() == "null")
writerWriteString(x, y, objToString());
else
writerWriteNumber(x, y, ConvertToDouble(objToString()));
break;
default:
writerWriteString(x, y, objToString());
break;
}
}
private static int Write(SqlDataReader reader, SystemUInt16 count, string fileName)
{
int iExp = count;
ExcelWriter writer = new ExcelWriter(fileName);
writerBeginWrite();
//写字段信息
for (SystemUInt16 j = 0; j < readerFieldCount; j++)
{
writerWriteString(0, j, readerGetName(j));
}
//循环一行一行读入数据
for (SystemUInt16 i = 1; i <= count; i++)
{
if (readerRead() == false)
{
iExp = i - 1;
break;
}
//循环一格一格写入数据
for (SystemUInt16 j = 0; j < readerFieldCount; j++)
{
WriteObject(writer, readerGetSqlValue(j), i, j);
}
}
writerEndWrite();
return iExp;
}
public class ExcelWriter
{
SystemIOFileStream _wirter;
//创建文件
public ExcelWriter(string strPath)
{
_wirter = new SystemIOFileStream(strPath, SystemIOFileModeOpenOrCreate);
}
//写数组
private void _writeFile(SystemUInt16[] values)
{
foreach (SystemUInt16 v in values)
{
byte[] b = SystemBitConverterGetBytes(v);
_wirterWrite(b, 0, bLength);
}
}
//写文件头
public void BeginWrite()
{
_writeFile(new SystemUInt16[] { 0x809, 8, 0, 0x10, 0, 0 });
}
//文件尾
public void EndWrite()
{
_writeFile(new SystemUInt16[] { 0xa, 0 });
_wirterClose();
}
//写数字到单元格
public void WriteNumber(SystemUInt16 x, SystemUInt16 y, double value)
{
_writeFile(new SystemUInt16[] { 0x203, 14, x, y, 0 });
byte[] b = SystemBitConverterGetBytes(value);
_wirterWrite(b, 0, bLength);
}
//写字符到单元格
public void WriteString(SystemUInt16 x, SystemUInt16 y, string value)
{
byte[] b = SystemTextEncodingDefaultGetBytes(value);
_writeFile(new SystemUInt16[] { 0x204, (SystemUInt16)(bLength + 8), x, y, 0, (SystemUInt16)bLength });
_wirterWrite(b, 0, bLength);
}
}
};
1、进去指定schema
数据库(存放了其他的数据库的信息)
use
information_schema
2、查询所有数据的大小
select
concat(round(sum(DATA_LENGTH/1024/1024),2),'MB')
as
data
from
TABLES
3、查看指定数据库的大小
比如说
数据库apoyl
select
concat(round(sum(DATA_LENGTH/1024/1024),2),'MB')
as
data
from
TABLES
where
table_schema='apoyl';
4、查看指定数据库的表的大小
比如说
数据库apoyl
中apoyl_test表
select
concat(round(sum(DATA_LENGTH/1024/1024),2),'MB')
as
data
from
TABLES
where
table_schema='apoyl'
and
table_name='apoyl_test';
整完了,有兴趣的可以试哈哦!挺使用哈
查看mysql数据库大小的四种办法,分别有以下四种:
第一种:进去指定schema
数据库(存放了其他的数据库的信息)
use
information_schema
第二种:查询所有数据的大小
select
concat(round(sum(DATA_LENGTH/1024/1024),2),'MB')
as
data
from
TABLES
第三种:查看指定数据库的大小,比如说:数据库apoyl
select
concat(round(sum(DATA_LENGTH/1024/1024),2),'MB')
as
data
from
TABLES
where
table_schema='apoyl';
第四种:查看指定数据库的表的大小,比如说:数据库apoyl
中apoyl_test表
select
concat(round(sum(DATA_LENGTH/1024/1024),2),'MB')
as
data
from
TABLES
where
table_schema='apoyl'
and
table_name='apoyl_test';
以上就是关于如何用sql统计数据库表的大小全部的内容,包括:如何用sql统计数据库表的大小、mysql 如何统计表大小、mysql怎么查看表占用空间大小等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)