Important! This is an automatic machine translated page. If you can read english, you should Click Here to read the original English version of the article.

Determine Size of a Table in SQL Server Determina dimensiunea de un tabel, în SQL Server

Ever wonder how big a table really is in your database? Fiecare mirare cum de mare un tabel este într-adevăr în baza de date? You know there are a million rows in the table, but how much space is that really taking? Ştii, există un milion de rânduri în tabel, dar cât de mult spaţiu este că într-adevăr a lua?

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 oferă o built-in depozitate procedura de care se pot executa cu uşurinţă pentru a arăta de mărimea unui tabel, inclusiv dimensiunea indicilor ... care ar putea să vă surprindă.

Syntax: Sintaxa:

sp_spaceused 'Tablename' sp_spaceused "TABLENAME"

Here's an example of it in action: Iată un exemplu de ea în acţiune:

Highly useful stuff. Foarte chestii utile. It's always interesting to see that the indexes are bigger than the actual data. Este întotdeauna interesant să vedem că indicii sunt mai mari decât datele reale.

This article was originally written on 03/27/07 Tagged with: Acest articol a fost scris iniţial pe 03.27.07 Etichetate cu: Database Baza de date , , SQL Server SQL Server

Daily Email Updates Daily Actualizări de email

You can get our how-to articles in your inbox each day for free. Aveţi posibilitatea să obţineţi modul nostru de-a articole în Inbox în fiecare zi pentru drum liber. Just enter your name and email below: Doar introduceţi numele dvs. şi e-mail de mai jos:


Name: Nume:
Email: E-mail:

Comments (9) Comentarii (9)

  1. sMiGuMp sMiGuMp

    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. În timp ce aceasta este o comandă utilă pentru determinarea spatiul alocat la un tabel, reţineţi că referinţele sp_spaceused sysindexes tabelul de sistem pentru a obţine atributele de spaţiu şi, uneori, ceea ce este stocat nu se poate obţine fie din Synch cu realitatea. 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). Dacă vedeţi numerele de spaţiu, care sunt aparent din lovitură puternică (în special pentru valoarea "nefolosite"), a alerga un "DBCC UPDATEUSAGE" comanda împotriva tabelul în cauză înainte de a rula sp_spacesued (sau împotriva intreaga baza de date, dacă aveţi timp şi nu sunt îngrijorat preliminar la degetele de la picioare cuiva).

    This can automatically be done as an optional parameter within sp_spaceused… Acest lucru poate fi făcut în mod automat ca un parametru opţional în termen de sp_spaceused ...

    eg sp_spaceused 'Orders',true de exemplu, sp_spaceused "ordine", true

    …or as separate commands as shown below. ... Sau ca comenzi separate, după cum se arată mai jos.

    To update usage stats for the entire current database, the syntax is: Pentru a actualiza statisticile de utilizare pentru intreaga baza de date actuale, sintaxa este:
    DBCC UPDATEUSAGE (0) DBCC UPDATEUSAGE (0)

    For a specific, named database: Pentru un anumit, baze de date pe nume:
    DBCC UPDATEUSAGE ('InsertdDbNameHere') DBCC UPDATEUSAGE ( "InsertdDbNameHere")

    For a specific table: Pentru o masă specifice:
    DBCC UPDATEUSAGE ('InsertdDbNameHere','InsertdTableNameHere') DBCC UPDATEUSAGE ( 'InsertdDbNameHere', 'InsertdTableNameHere')

    You can always check BOL for all the details on DBCC UPDATEUSAGE Puteţi verifica mereu BOL pentru toate detaliile privind DBCC UPDATEUSAGE

  2. Charles tucker Tucker Charles

    Thank you, using query analyer and running procedure sp_spaceused is helpful, however, what if your database has close too 100 tables. Vă mulţumesc, folosind analyer interogare şi procedura de rulare sp_spaceused este de ajutor, cu toate acestea, ce se întâmplă dacă baza de date dvs. are prea aproape 100 tabele. Anyway to return the entire database size? Oricum pentru a reveni dimensiunea intreaga baza de date?

  3. Rick Rick

    I just found this, it returns spaceused for each table: Tocmai am gasit asta, acesta revine spaceused pentru fiecare tabel:

    EXEC sp_MSforeachtable @command1=”EXEC sp_spaceused '?'” EXEC sp_MSforeachtable @ Command1 = "EXEC sp_spaceused '?" "

  4. Sanjiv Sanjiv

    Charles sp_helpdb Sp_helpdb Charles

  5. Brian Brian

    Rick – that is one of the most useful sql server commands of all time. Rick - faptul că este una dintre cele mai utile comenzile SQL Server din toate timpurile. You are the greatest. Esti cel mai mare.

  6. LNu76 LNu76

    I tried to use Ricks Tipp, but having 181 Tables in the Database didnt do it much good. Am încercat să folosească Ricks Tipp, dar care au 181 tabelele din baza de date didnt face mult bine. 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. De asemenea, Mechanic sale cu sp_spaceused trataţi fiecare tabel ca o interogare de independent, ceea ce a făcut imposibilă utilizarea într-o creştere automată-de-Baza de date statistice.

    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): Am furat / imprumutat logica sp_spaceused şi a aplicat-o la vizualizarea următoare (pe care am acum adăugaţi la un tabel Statistica, care pot fi apoi interogate în mai multe moduri):

    SELECT SELECTATI
    TableName, TABLENAME,
    NumRows, NumRows,
    reservedpages *8192/1024 as TotalSpace, reservedpages * 8192/1024 ca TotalSpace,
    pages * 8192/1024 as DataSpace, pages * 8192/1024 ca DataSpace,
    (usedpages-pages)*8192/1024 as IndexSpace, (usedpages-pagini) * 8192/1024 ca IndexSpace,
    (reservedpages-usedpages)*8192/1024 as UnusedSpace (reservedpages-usedpages) * 8192/1024 ca UnusedSpace

    FROM (SELECT De la (SELECT
    t.[name] as tablename, t. [numele] ca TABLENAME,
    avg([rows]) as NumRows, med ([rânduri]) ca NumRows,
    sum(total_pages) as reservedpages, suma (total_pages) ca reservedpages,
    sum(used_pages) as usedpages, suma (used_pages) ca usedpages,
    sum( suma (
    CASE CAZ
    When it.internal_type IN (202,204) Then 0 Când it.internal_type IN (202204) Apoi 0
    When a.type 1 Then a.used_pages Când a.type 1 Atunci a.used_pages
    When p.index_id Când p.index_id

  7. LNu76 LNu76

    Bah, it got cut off, here is the rest: Bah, it luat tăiate, aici este restul:

    When p.index_id Când p.index_id

  8. LNu76 LNu76

    When p.index_id Când p.index_id

  9. LNu76 LNu76

    (smaller than sign – why doesnt it take it here?) 2 Then a.data_pages (mai mic decât semn - de ce doesnt it ia-o aici?) 2 Atunci a.data_pages
    Else 0 Else 0
    END) as pages END) ca pagini
    from sys.allocation_units as a Join sys.partitions as p on p.partition_id = a.container_id de la sys.allocation_units ca o sys.partitions ta ca pe p.partition_id p = a.container_id
    left join sys.internal_tables it on p.object_id = it.object_id stânga se alăture sys.internal_tables-l pe p.object_id = it.object_id
    JOIN sys.tables as t on p.object_id=t.object_id JOIN sys.tables ca t pe p.object_id = t.object_id
    –WHERE t.name='mittra' -Unde t.name = 'mittra'
    group by t.[name]) as subselect grup de T. [nume]), ca subselect


Leave a Comment Lăsaţi un comentariu




Leave your Leave tău friendly prietenoasa comment here. comentariu aici.

If you have a computer help question, Dacă aveţi un calculator ajuta la întrebare, click here to leave it on the forums click aici pentru a lăsa pe forum instead. în schimb.

Note: Your comment may not show up immediately on the site. Notă: Comentariul dvs. să nu apară imediat pe site-ul.

Our Friends Our Friends
Getting Started Noţiuni de bază


About How-To Geek Despre "Cum să" Geek
What Is That Process? Ce este acest proces?
svchost.exe svchost.exe
jusched.exe winampa.exe
dwm.exe dwm.exe
ctfmon.exe ctfmon.exe
wmpnetwk.exe wmpnetwk.exe
wmpnscfg.exe wmpnscfg.exe
rundll32.exe rundll32.exe
wfcrun32.exe wfcrun32.exe
Ipoint.exe Ipoint.exe
Itype.exe Itype.exe
Wfica32.exe Wfica32.exe
Mobsync.exe Mobsync.exe
conhost.exe conhost.exe
Dpupdchk.exe Dpupdchk.exe Adobe_Updater.exe Adobe_Updater.exe

Copyright © 2006-2009 HowToGeek.com. Copyright © 2006-2009 HowToGeek.com. All Rights Reserved. Toate drepturile rezervate.