开发者

Retrieving MS SQL database size in culture independent format

sp_helpdb returns strings like '50000.255 MB' in the db_size column.

These strings are culture-dependent; the above string will mean 2 different things in US and Germany (in the latter, the dot char is used as a group separator, similar to the comma in开发者_C百科 US).

Is there another method which returns a numeric value, culture-independent?


 Use YourDB;
 SELECT SUM(Size / 128.0) As FileSize from sys.database_files;

This returns the size in MB as a numeric, you should be able to do what you like with it from there.

Note: size returns the number of 8KB pages in a given database file.

http://msdn.microsoft.com/en-us/library/ms174397.aspx


I do not think it is possible. The SP sp_helpdb uses str to convert the numeric size to varchar and there is nothing in the documentation (that I can find) that can make str use , instead of . as decimal symbol. Using set language does not help.

Workaround as suggested by Martin in comment

select replace(str(sum(convert(dec(17,2),size)) / 128,10,2) +' MB', '.', ',') 
from sys.database_files
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜