Author |
Topic |
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2005-08-16 : 12:09:45
|
I can't remember if I posted this already or not:CREATE PROCEDURE sp_space @sortbyrows bit=0 ASSET NOCOUNT ONselect cast(object_name(id) as varchar(50)) AS name, sum(CASE WHEN indid<2 THEN rows END) AS rows,sum(reserved)*8 AS reserved, sum(dpages)*8 AS data, sum(used-dpages)*8 AS index_size, sum(reserved-used)*8 AS unusedfrom sysindexes with (nolock) where indid in(0,1,255) and id>100 GROUP BY id with rollupORDER BY CASE WHEN @sortbyrows=1 THEN sum(CASE WHEN indid<2 THEN rows END) ELSE sum(reserved)*8 END descUsage:EXEC sp_space --show stats sorted by reserved space sizeEXEC sp_space 1 --show stats sorted by row countIt basically displays the results of sp_spaceused, but broken out by each table, and it rolls it up to a grand total. Naturally, for the most accurate results you should run DBCC UPDATEUSAGE before running this sproc. |
|
maxim
Yak Posting Veteran
51 Posts |
Posted - 2007-01-13 : 20:13:10
|
Please, forgive my question...I run your sp and see "total data = 466" But in what units ? 466 bytes??The host company who host my site give 250 Mb space to sql server...does it means that my "data" showed on by your sp can up to 250000 ?Thanks for your sp! |
|
|
X002548
Not Just a Number
15586 Posts |
|
maxim
Yak Posting Veteran
51 Posts |
Posted - 2007-01-14 : 16:10:28
|
:( You didn't answer me !which the units of the field “data” generated by this procedure? |
|
|
jezemine
Master Smack Fu Yak Hacker
2886 Posts |
Posted - 2007-01-14 : 20:48:20
|
this is a free forum. you get what you pay for. if you want to know the units, why don't you read the query and try to figure it out? it's hitting the sysindexes table. so lookup the sysindexes table in BOL and see what the units of the column in question are: http://msdn2.microsoft.com/en-us/library/ms190283.aspxThere you'll find that dpages contains the number of pages used. that, combined with the knowledge that there is 8kb on a page, is your answer. If you didn't know a page is 8kb, you can google that too:http://www.google.com/search?q=page+size+sql+serverthe first link that comes up has it. so the units of the "data" column in the function above are in kb. moral: google is your friend. edit: fixed link. www.elsasoft.org |
|
|
maxim
Yak Posting Veteran
51 Posts |
Posted - 2007-01-15 : 14:43:48
|
thanks jezemine!However, when i run sp_spaceused the results are diferent (most diferent) from the results with this procedure!If you can answer this :When my host company tell that i only have 200 Mb for use sql, thats the data field * 1024 right?or my database uses more memory than the listed in the field “data”? I am not very exeperiente in mssql. I only wanted to use this procedure to know the total size of my database and when he is full |
|
|
jezemine
Master Smack Fu Yak Hacker
2886 Posts |
Posted - 2007-01-15 : 16:45:28
|
if you just want to know the size of the db, sp_spaceused is adequate, look at the first result set it returns for that. use AdventureWorksexec sp_spaceuseddatabase_name database_size unallocated space-------------- ------------------ ------------------AdventureWorks 181.94 MB 15.16 MBreserved data index_size unused------------------ ------------------ ------------------ ------------------168736 KB 84096 KB 77960 KB 6680 KB www.elsasoft.org |
|
|
maxim
Yak Posting Veteran
51 Posts |
Posted - 2007-01-15 : 17:14:07
|
thanks very much jezemineI try this procedure and receive a total size = 13 MbThen i clear my custom table "backups" and then my total size up to 16 Mb !!!!!This fields space is bigger in log file than sql tableIf i can't find a way to clean my log file i'll go to 200 Mb soon!Thanks Jezemine! |
|
|
ksampatk
Starting Member
3 Posts |
Posted - 2010-04-12 : 11:02:29
|
Try below query to fetch SQL Database Sizeselect db_name(dbid),str(convert(dec(15),sum(size))* 8192/ 1048576,10,2)+ N' MB' as Size from sys.sysaltfiles group by dbid order by 2 descGOSampath Karnatakam - DBA Architect |
|
|
ksampatk
Starting Member
3 Posts |
Posted - 2010-04-12 : 11:02:30
|
Try below query to fetch SQL Database Sizeselect db_name(dbid),str(convert(dec(15),sum(size))* 8192/ 1048576,10,2)+ N' MB' as Size from sys.sysaltfiles group by dbid order by 2 descGOSampath Karnatakam - DBA Architect |
|
|
ShamanDBA
Starting Member
2 Posts |
Posted - 2010-06-14 : 13:20:04
|
Here is a real simple oneSELECT DatabaseName, ROUND(SUM(DataSize)/1024,0) AS DataSizeMB, ROUND(SUM([LogSize])/1024,0) AS LogSizeMBFROM( SELECT DB_NAME(database_id) AS DatabaseName, CAST( CASE [type] WHEN 0 THEN (CAST([size] AS float) * CAST(8192 AS float))/1024 ELSE 0 END AS float)AS DataSize, CAST( CASE [type] WHEN 1 THEN (CAST([size] AS float) * CAST(8192 AS float))/1024 ELSE 0 END AS float)AS LogSize FROM sys.[master_files] ) DatabaseSizesGROUP BY [DatabaseName] |
|
|
|