July 2, 2008 at 12:53 pm
Hey all,
I created a view to help assist in showing all data and log file sizes (and some other stuff), but I'd like to be able to keep it as a view and not take it to a procedure. The reason I'd have to take it a procedure is to be within the context of the database to use the FILEPROPERTY function.
Any alternative to how I did this to retrieve the used/unused space?
Thanks
July 2, 2008 at 12:57 pm
Why would you have to make it a proc to use a function like FileProperty? Just set the right columns to be the input parameters, and use Cross Apply instead of Join. (Look up Cross Apply in Books Online.)
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
July 2, 2008 at 1:00 pm
GSquared (7/2/2008)
Why would you have to make it a proc to use a function like FileProperty? Just set the right columns to be the input parameters, and use Cross Apply instead of Join. (Look up Cross Apply in Books Online.)
Maybe I'm missing something, but according to BOL:
Arguments
file_name
Is an expression that contains the name of the file associated with the current database for which to return property information. file_name is nchar(128).
property
Is an expression that contains the name of the file property to return. property is varchar(128), and can be one of the following values.
Meaning that I have to be in the context of the database.
July 2, 2008 at 1:01 pm
You can use the script on this link to get information on all databases on a server at the same time.
Get Server Database File Information
July 2, 2008 at 1:10 pm
Michael Valentine Jones (7/2/2008)
You can use the script on this link to get information on all databases on a server at the same time.Get Server Database File Information
Thanks, but not what I'm looking for.
July 3, 2008 at 6:23 am
Any assistance would be much appreciated.
Thanks
July 7, 2008 at 9:23 am
Shameless bump ...
September 23, 2008 at 1:51 pm
Forgot about this ... back to it. Yeah I could turn it into a proc and cursor through and update a temp table, but I really want to keep this as a view. Anyone know of a different way to determine the used/unused without using FILEPROPERTY?
I'm gonna start on pulling out the unallocated from sp_spaceused ... perhaps I can use that.
Thanks
May 6, 2010 at 1:33 pm
Adam,
It's been a while so I hope you already found your answer. If not, Tim Ford had a good tip to put this at the beginning of your foreachdb command - 'Use [' + '?' + '] ...'
http://www.mssqltips.com/tip.asp?tip=1426
Cheers
Shannon
May 6, 2010 at 1:36 pm
shannon714 (5/6/2010)
Adam,It's been a while so I hope you already found your answer. If not, Tim Ford had a good tip to put this at the beginning of your foreachdb command - 'Use [' + '?' + '] ...'
http://www.mssqltips.com/tip.asp?tip=1426
Cheers
Shannon
Thanks shannon, but not something I like to do. I was able to do what I needed, just had to resort to dynamic SQL and make a procedure.
May 11, 2010 at 3:49 am
You can use DBCC SHOWFILESTATS WITH NO_INFOMSGS. It will provide you the file_id_, file_group, total_extents, used_extents, File name, file_Location)
Thanks
Neeraj
April 11, 2014 at 7:34 am
So, SP_spaceUsed worked for you?
I am working on the similar where I am using this(below) which works fine except (tempdb-->templog [log file])
So, I am also looking for alternate to eliminate the exception. 🙂
SELECT
FILEPROPERTY(DF.name, 'SpaceUsed')/128.0
FROM sys.databases D WITH(NOLOCK)
JOIN sys.master_files DF WITH(NOLOCK)
ON D.database_id = DF.database_id
Viewing 12 posts - 1 through 11 (of 11 total)
You must be logged in to reply to this topic. Login to reply