Determine Size of a Table in SQL Server Určite Veľkosť tabuľky v SQL Serveru
Ever wonder how big a table really is in your database? Niekedy, ako veľký stôl je naozaj v databáze? You know there are a million rows in the table, but how much space is that really taking? Vieš, že existuje milión riadkov v tabuľke, ale koľko je to naozaj užívať?
SQL Server provides a built-in stored procedure that you can run to easily show the size of a table, including the size of the indexes… which might surprise you. SQL Server poskytuje stavaný z-do uloženej procedúry, ktoré môžete spustiť ľahko ukázať veľkosť tabuľky, vrátane veľkosti indexy ..., ktoré by mohli prekvapiť.
Syntax: Syntax:
sp_spaceused 'Tablename' sp_spaceused 'TableName'
Here's an example of it in action: Tu je príklad z toho v akcii:

Highly useful stuff. Veľmi užitočné veci. It's always interesting to see that the indexes are bigger than the actual data. Je vždy zaujímavé vidieť, že indexy sú väčšie, ako aktuálne dáta.

Daily Email Updates Denný Svářeč
You can get our how-to articles in your inbox each day for free. Môžete si naše jak-na články vo vašej schránky každý deň zadarmo. Just enter your name and email below: Stačí zadať svoje meno a e-mail nižšie:



While this is a useful command for determining the space allocated to a table, keep in mind that sp_spaceused references the sysindexes system table to get the space attributes and sometimes what's stored there can get be out of synch with reality. To je síce užitočné príkaz na určenie miesta prideleného stola, majte na pamäti, že sp_spaceused odkazy sysindexes systémovej tabuľky dostať priestor atribúty a niekedy to, čo je v ňom uložené môže dostať sa von synchronizácia s realitou. If you see space numbers that are seemingly out of whack (especially for the 'unused' value), run a “DBCC UPDATEUSAGE” command against the table in question before running sp_spacesued (or against the entire database if you have time and aren't worried about stepping on anyone's toes). Ak vidíte namiesto čísla, ktoré sú zdanlivo v neporiadku (najmä pre 'nepoužité' hodnota), spustite "DBCC UPDATEUSAGE" príkaz proti tabuľky v otázke pred spustením sp_spacesued (alebo proti celej databázy, ak máte čas a nie sú obáva šliapať na niečie prsty).
This can automatically be done as an optional parameter within sp_spaceused… To možno uskutočňovať automaticky ako voliteľný parameter v sp_spaceused ...
eg sp_spaceused 'Orders',true napr sp_spaceused 'Objednávky', true
…or as separate commands as shown below. ... Alebo ako samostatné príkazy, ako je uvedené nižšie.
To update usage stats for the entire current database, the syntax is: Ak chcete aktualizovať využitie štatistík pre celý existujúcej databáze, Syntax je:
DBCC UPDATEUSAGE (0) DBCC UPDATEUSAGE (0)
For a specific, named database: Pre konkrétne, pomenovaný databázy:
DBCC UPDATEUSAGE ('InsertdDbNameHere') DBCC UPDATEUSAGE ( 'InsertdDbNameHere')
For a specific table: Pre konkrétne tabuľka:
DBCC UPDATEUSAGE ('InsertdDbNameHere','InsertdTableNameHere') DBCC UPDATEUSAGE ( 'InsertdDbNameHere', 'InsertdTableNameHere')
You can always check BOL for all the details on DBCC UPDATEUSAGE Môžete vždy skontrolovať BOL pre všetky podrobnosti o DBCC UPDATEUSAGE
Thank you, using query analyer and running procedure sp_spaceused is helpful, however, what if your database has close too 100 tables. Ďakujem, s použitím dotazu analyer a prevádzku sp_spaceused postup je užitočné, ale čo keď má vaša databáza príliš blízko 100 tabuliek. Anyway to return the entire database size? Každopádne sa vrátiť celej databázy veľkosť?
I just found this, it returns spaceused for each table: Len som našiel to, vráti sa spaceused u každej tabuľky:
EXEC sp_MSforeachtable @command1=”EXEC sp_spaceused '?'” EXEC sp_MSforeachtable @ příkaz1 = "EXEC sp_spaceused''?"
Charles sp_helpdb Charles sp_helpdb
Rick – that is one of the most useful sql server commands of all time. Rick - to je jeden z najužitočnejších SQL Server príkazy všetkých dôb. You are the greatest. Ste najlepší.
I tried to use Ricks Tipp, but having 181 Tables in the Database didnt do it much good. Snažil som sa použiť Ricks Tipp, ale s 181 tabuliek v databáze didnt urobiť veľa dobrého. Also, his Mechanic with sp_spaceused treated each Table as a standalone query, wich made it impossible to use in an automated Growth-of-Database Statistic. Aj jeho sp_spaceused Mechanik postrekované každého stola ako samostatný dotaz, ktorý znemožnil použitie v automatizovaných rast-z-Štatistické databázy.
I stole/borrowed the logic of sp_spaceused and applied it to the following VIEW (wich I now add to a Statistics Table, wich can then be queried in several ways): Som ukradol / vypožičal logiku sp_spaceused a aplikovali na nasledujúci pohľad (čo by som teraz pridať do štatistiky tabuľky, ktoré potom môžu nazerať niekoľkými spôsobmi):
SELECT SELECT
TableName, TableName,
NumRows, NumRows,
reservedpages *8192/1024 as TotalSpace, reservedpages * 8192/1024 ako TotalSpace,
pages * 8192/1024 as DataSpace, strán * 8192/1024 ako DataSpace,
(usedpages-pages)*8192/1024 as IndexSpace, (usedpages-pages) * 8192/1024 ako IndexSpace,
(reservedpages-usedpages)*8192/1024 as UnusedSpace (reservedpages-usedpages) * 8192/1024 ako UnusedSpace
FROM (SELECT FROM (SELECT
t.[name] as tablename, t. [name] as tablename,
avg([rows]) as NumRows, avg ([riadkov]) ako numRows,
sum(total_pages) as reservedpages, sum (total_pages) ako reservedpages,
sum(used_pages) as usedpages, sum (used_pages) ako usedpages,
sum( sum (
CASE CASE
When it.internal_type IN (202,204) Then 0 Keď it.internal_type IN (202204) Then 0
When a.type 1 Then a.used_pages Keď a.type 1 Then a.used_pages
When p.index_id Keď p.index_id
Bah, it got cut off, here is the rest: Pch, to mám odrezať, tu je zvyšok:
When p.index_id Keď p.index_id
When p.index_id Keď p.index_id
(smaller than sign – why doesnt it take it here?) 2 Then a.data_pages (menšie ako podpísať - prečo doesnt brať to tady?) 2 Potom a.data_pages
Else 0 Else 0
END) as pages END) ako stránky
from sys.allocation_units as a Join sys.partitions as p on p.partition_id = a.container_id od sys.allocation_units ako sys.partitions Zaregistrujte sa ako p o p.partition_id = a.container_id
left join sys.internal_tables it on p.object_id = it.object_id left join sys.internal_tables ho na p.object_id = it.object_id
JOIN sys.tables as t on p.object_id=t.object_id JOIN sys.tables ako t o p.object_id = t.object_id
–WHERE t.name='mittra' KDE-t.name = 'mittra'
group by t.[name]) as subselect skupiny t. [name]) ako subselect