Sql-server – Limit a database’s max disk size and limit user total database size usage

sql serversql-server-2008

Is there a way to do this in SQL Server 2008 express?

I need to limit the maximum allowed size of a specific database.

I also would like to limit the maximum allowed total size of databases for a specific user.

Is this possible and how, thank you.

Best Answer

The file is relatively simple compared to the user size restriction.

alter database test 
modify file
(
  name = 'test_datafile1'
  ,MaxSize = 5 GB
)

With the user restriction you may try one of the following based upon your database design.

  1. Log the row owner and calculate the size of the row based on the datatype(s) and their corresponding storage requirements. Then multiply by the number of rows that the user 'owns'
  2. query the size of the table that the user 'owns' to determine if they have exceeded the limit.

It is a little difficult to say which way would work best because if all user data is in the same table versus separate tables then the approach will be entirely different.

HTH