PDA

View Full Version : فهمیدن حجم جداول تولید شده



oliya24
چهارشنبه 30 شهریور 1390, 01:58 صبح
سلام و خسته نباشید
1:چطور میتونم بفهمم که جدولی رو که ساختم چه قدر فضفا رو اشغال کرده البته بدون داده
2:حالا وقتی که داخل یه جدول اطلاعات باشه چی؟؟؟از چه دستوری استفاده میشه؟؟؟؟؟؟

Felony
چهارشنبه 30 شهریور 1390, 10:05 صبح
میتونی از StoredProcedure زیر استفاده کنی :

USE [master]
GO
/****** Object: StoredProcedure [dbo].[GetAllTableSizes] Script Date: 09/21/2011 10:12:23 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[GetAllTableSizes]
AS
/*
Obtains spaced used data for ALL user tables in the database
*/
DECLARE @TableName VARCHAR(100) --For storing values in the cursor

--Cursor to get the name of all user tables from the sysobjects listing
DECLARE tableCursor CURSOR
FOR
select [name]
from dbo.sysobjects
where OBJECTPROPERTY(id, N'IsUserTable') = 1
FOR READ ONLY

--A procedure level temp table to store the results
CREATE TABLE #TempTable
(
tableName varchar(100),
numberofRows varchar(100),
reservedSize varchar(50),
dataSize varchar(50),
indexSize varchar(50),
unusedSize varchar(50)
)

--Open the cursor
OPEN tableCursor

--Get the first table name from the cursor
FETCH NEXT FROM tableCursor INTO @TableName

--Loop until the cursor was not able to fetch
WHILE (@@Fetch_Status >= 0)
BEGIN
--Dump the results of the sp_spaceused query to the temp table
INSERT #TempTable
EXEC sp_spaceused @TableName

--Get the next table name
FETCH NEXT FROM tableCursor INTO @TableName
END

--Get rid of the cursor
CLOSE tableCursor
DEALLOCATE tableCursor

--Select all records so we can use the reults
SELECT *
FROM #TempTable

--Final cleanup!
DROP TABLE #TempTable

برای اجرا :

EXEC GetAllTableSizes

oliya24
چهارشنبه 30 شهریور 1390, 13:14 عصر
دوست عزیز من متوجه نشدم میشه یکم واضح تر توضیح بدید
از این رویه میشه استفاده کرد
exec sp_spaceuced 'نام جدول'