Solved

How to know database size in SQL?

Posted on 2011-02-28
6
489 Views
Last Modified: 2012-05-11
Hi Experts,

I want to know the size of Primavera database in SQL 2005. Please tell me how thanks
0
Comment
Question by:ragot
6 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 35004615
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
 

Author Comment

by:ragot
ID: 35004629
im using sql express only
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 35004633
Do you have management studio for SQL Express?
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:ragot
ID: 35004640
nope i dont have
0
 
LVL 10

Expert Comment

by:John Claes
ID: 35004702
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
 
LVL 40

Expert Comment

by:Sharath
ID: 35004829
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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question