Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
lincsSql
Starting Member
1 Post |
Posted - 2009-08-16 : 20:44:00
|
| Hi All I would like to know Datbase crdate, Size for one of my project. I find some info from google but now I am stuck as Size is only working for current datbase but I need to know Size of databse what I am passing in parameters. See the query below and tell me how can i get size for every differnet database.Note: I am calling this store procedure from .Net code.USE [xxx]GOSET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGO-- =============================================-- Author: xx-- Create date: <Create Date,,>-- Description: Get Database Create Datae,Physical File Location and Size-- =============================================CREATE PROCEDURE [dbo].[db_sp_test] -- Add the parameters for the stored procedure here @databaseName nvarchar(1000) ASBEGIN declare @fileNameFromDatabase nvarchar(1000) ,@query nvarchar(1000) ,@pages bigint ,@queryFORSIZE varchar(200) select @pages = sum( CASE When it.internal_type IN (202,204) Then 0 When a.type <> 1 Then a.used_pages When p.index_id < 2 Then a.data_pages Else 0 END ) from sys.partitions p join sys.allocation_units a on p.partition_id = a.container_id left join sys.internal_tables it on p.object_id = it.object_id --select data = ltrim(str(@pages * 8192 / 1024.,15,0) + ' KB') select crdate,filename,(select ltrim(str(@pages * 8192 / 1024.,15,0) + ' KB')) as size from master..sysdatabases where name =@databaseNameEND |
|
|
|
|
|
|
|