הצטרפו לקבוצות שלנו לקבלת עדכונים מרוכזים פעם בשבוע:

ווטסאפ:
http://wa.dwh.co.il
טלגרם:
http://telegram.dwh.co.il

סקריפט לחישוב גודל טבלאות בבסיס נתונים

More
17 years 1 week ago #3980 by eldad
מחסן הנתונים שלכם מתפוצץ ואתם צריכים להבין מה גורם לזה?
תריצו את הסקריפט ותראו איזו טבלה תופסת כמה:


SET NOCOUNT ON
/*
@Sort bit VALUES
0 = Alphabetically BY TABLE name
1 = Sorted BY total space used by TABLE
*/
DECLARE @cmdstr varchar(100)
DECLARE @Sort bit
SELECT @Sort = 0 /* Edit this value FOR sorting options */
/* DO NOT EDIT ANY CODE BELOW THIS LINE */
--Create Temporary Table
CREATE TABLE #TempTable
( [Table_Name] varchar(50),
Row_Count int,
Table_Size varchar(50),
Data_Space_Used varchar(50),
Index_Space_Used varchar(50),
Unused_Space varchar(50)
)
--Create Stored Procedure String
SELECT @cmdstr = 'sp_msforeachtable ''sp_spaceused "?"'''
--Populate Tempoary Table
INSERT INTO #TempTable EXEC(@cmdstr)
--Determine sorting method
IF @Sort = 0


    BEGIN
    --Retrieve Table Data and Sort Alphabet
    --    ically
    SELECT * FROM #TempTable ORDER BY Table_Name
END


ELSE


    BEGIN
    /*Retrieve TABLE Data AND Sort BY the size OF the Table*/
    SELECT * FROM #TempTable ORDER BY Table_Size DESC
END


--Delete Temporay Table
DROP TABLE #TempTable

Please התחברות to join the conversation.

Moderators: eldad
Time to create page: 0.257 seconds