2

I'm trying to query the maximum size of a SQL Azure database using code from this answer:

SELECT CONVERT(BIGINT, DATABASEPROPERTYEX('DatabaseOfInterestName', 'MaxSizeInBytes')) / 1024

The problem is I need to pass the database name there. Since I need this code in a Windows Azure application which has different configurations - for production use, for automatic build and for testing - and each configuration would use its own database I'll have to pass the database name into that SQL query and that's some extra wiring in my code.

Is there a way to tell DATABASEPROPERTYEX() to query the property "from the current database" without specifying the database name explicitly?

Community
  • 1
  • 1
sharptooth
  • 167,383
  • 100
  • 513
  • 979

2 Answers2

3

Would the DB_NAME() function do your job?

SELECT CONVERT(BIGINT, DATABASEPROPERTYEX(DB_NAME(), 'MaxSizeInBytes')) / 1024
Paddy
  • 33,309
  • 15
  • 79
  • 114
2

No and yes. No, you can not get DATABASEPROPERTYEX to use the current database.

BUt there is SQL to get the current database ;)

http://blog.sqlauthority.com/2008/02/12/sql-server-get-current-database-name/

The answer is:

SELECT DB_NAME() AS DataBaseName

;)

Use DB_NAME() as input to DATABASEPROPERTYEX.

TomTom
  • 61,059
  • 10
  • 88
  • 148