title: How to get MS SQL Server and database space info in straigthforward, simple way
body: <p>I'm developing an app for which I need some simple information about a given Microsoft SQL Server:</p>
  
  <ul>
  <li>The maximum size the server supports¹</li>
  <li>The total free space still available for a database to grow²</li>
  </ul>
  
  <p>I googled about this and even though there are many pages on the matter with many different answers, I couldn't find anything that suits me because either it was too fancy (e.g. writting complex tables to files) or didn't actually work. The context I'm in is a simple software to manage the database; it will get those info, store in integer variables and then use them to work. So my idea here is simply to do a query, select style, grab one data and move on. An example of the only "function" I managed to find that would fit these criteria:</p>
  
  <pre><code>SELECT size FROM sys.master_files WHERE DB_NAME(database_id) = \'DB_NAME_HERE\'²
  </code></pre>
  
  <p>(Note: this is just an example, the function doesn't actually return what I want) </p>
  
  <p>¹: For example, the Express editions may have up til 10Gb of allowed storage capacity (<a href="https://stackoverflow.com/questions/51614936/is-there-a-limit-size-for-a-sql-server-database/51614960#">it depends on the version</a>). So the function here should return a value close to that.</p>
  
  <p>²: In advance: to know my database's size doesn't matter since it's a server with many databases. My app's logic needs the free space available for any database to grow, so calculating "total space - my db space" won't work.</p>