SQL Server Virtual File Stats

As anyone knows who's worked with SQL Server for more than about 10 minutes - she's I/O intensive - especially when under high memory pressure. So... exactly which one of your databases is reading and writing more than the others? Does your database read more than it writes? If so, by how much? How many IOPS has it encountered and how large were those logical IOPS?

Well, let me tell you - the answer is a lot easier than you might think. This simple script will spit out all of that crucial information about each database file (both data and log). Check it out for yourself!

SELECT
	DB_NAME(vfs.DbId) DatabaseName,
	mf.name,
	mf.physical_name,
	vfs.BytesRead,
	vfs.BytesWritten,
	vfs.IoStallMS,
	vfs.IoStallReadMS,
	vfs.IoStallWriteMS,
	vfs.NumberReads,
	vfs.NumberWrites,
	(size*8)/1024 Size_MB
FROM
	fn_virtualfilestats(NULL,NULL) vfs
INNER JOIN sys.master_files mf
	ON mf.database_id = vfs.DbId
	AND mf.file_id = vfs.FileId