• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 497
  • Last Modified:

How to know database size in SQL?

Hi Experts,

I want to know the size of Primavera database in SQL 2005. Please tell me how thanks
0
ragot
Asked:
ragot
1 Solution
 
Carl TawnSystems and Integration DeveloperCommented:
If you have Management Studio, right-click on the database and then from the context menu choose Reports > Standard Reports > Disk Usage

That will give you a break down of disk usage of your database.
0
 
ragotAuthor Commented:
im using sql express only
0
 
Carl TawnSystems and Integration DeveloperCommented:
Do you have management studio for SQL Express?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
ragotAuthor Commented:
nope i dont have
0
 
John ClaesCommented:
If you're only using a Query based GUID

You might use the folowing Stored procedure
It gives the information for every Table.

I've added a extra summing query to get the data for the database ;-)


 
CREATE PROCEDURE GetAllTableSizes
AS
/*
    Obtains spaced used data for ALL user tables in the database
*/
DECLARE @TableName VARCHAR(100)      --For storing values in the cursor
DECLARE @TableSchema 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 sysobjects.[name],sys.schemas.[name]
from sysobjects
INNER JOIN sys.schemas ON sysobjects.uid  = sys.schemas.schema_id 
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, @TableSchema

--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
	declare @TableFullName varchar(201)
	set @TableFullName= @TableSchema + '.' + @TableName
print @TableFullName
    INSERT  #TempTable
        EXEC sp_spaceused @TableFullName

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

--Get rid of the cursor
CLOSE tableCursor
DEALLOCATE tableCursor

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

SELECT 
	sum(convert(int,numberofRows)) numberofRows,
	sum(convert(int,substring(reservedSize,0,len(reservedSize)-3))) reservedSize,
	sum(convert(int,substring(dataSize    ,0,len(dataSize    )-3))) dataSize,
	sum(convert(int,substring(indexSize   ,0,len(indexSize   )-3))) indexSize,
	sum(convert(int,substring(unusedSize  ,0,len(unusedSize  )-3))) unusedSize
FROM #TempTable

--Final cleanup!
DROP TABLE #TempTable

GO

Open in new window

0
 
SharathData EngineerCommented:
Run this and see the database_size column value.
exec dbName..sp_spaceused

If your db name is Primavera, then run exec Primavera..sp_spaceused
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now