Sql-server – Pages to MB, multiple and divide or just divide

database-sizesql server

When you are using things like sys.database_files it gives size of the file, in 8-KB pages, while many other things you are comparing to it to are in MB.

There are a number of ways to convert the 8-KB pages to MB, several ways are offered in the answers to Query to report disk space allocation and used space

The two most common are

  • Multiple by 8 and divide by 1024 (128000 * 8 / 1024 = 100)
  • Divide by 128 (128000 / 128 = 100)

The second is simpler, requiring only a single operation. But both seem to give the same answer.

Is there a good reason to choose one method over the other?

Best Answer

It's simple math. Those common equations are the same (not seem to give the same answer).

Simpler notation is the only benefit of the second one.

The first one just exlpains from where is the number 128 (8KB per page divides by 1024KB for MB size).