Solved

How to know database size in SQL?

Posted on 2011-02-28
6
478 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
Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to shrink a transaction log file down to a reasonable size.

744 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now