I tried the following on SQL-Server:
我在SQL-Server上尝试了以下内容:
create table #TmpLOGSPACE(
DatabaseName varchar(100)
, LOGSIZE_MB decimal(18, 9)
, LOGSPACE_USED decimal(18, 9)
, LOGSTATUS decimal(18, 9))
insert #TmpLOGSPACE(DatabaseName, LOGSIZE_MB, LOGSPACE_USED, LOGSTATUS)
DBCC SQLPERF(LOGSPACE);
...but this rises an syntax-error...
...但这会增加语法错误......
Any sugestions?
任何sugestions?
2 个解决方案
#1
20
Put the statement to be run inside EXEC('')
将语句放在EXEC('')中运行
insert #TmpLOGSPACE(DatabaseName, LOGSIZE_MB, LOGSPACE_USED, LOGSTATUS)
EXEC('DBCC SQLPERF(LOGSPACE);')
#2
1
This does not directly answer the question, but it does answer the intent of the question: presumably, you want a simple way to find the current size of the log file:
这并没有直接回答这个问题,但它确实回答了问题的意图:大概,你想要一种简单的方法来查找日志文件的当前大小:
SELECT size*8192.0/1024.0/1024.0 as SizeMegabytes
FROM sys.database_files
WHERE type_desc = 'LOG'
-- If the log file size is 100 megabytes, returns "100".
The reason why we multiply by 8192 is that the page size in SQL server is 8192 bytes.
我们乘以8192的原因是SQL Server中的页面大小是8192字节。
The reason why we divide by 1024, then again by 1024, is to convert the size from bytes to megabytes.
我们除以1024,然后再除以1024的原因是将大小从字节转换为兆字节。
#1
20
Put the statement to be run inside EXEC('')
将语句放在EXEC('')中运行
insert #TmpLOGSPACE(DatabaseName, LOGSIZE_MB, LOGSPACE_USED, LOGSTATUS)
EXEC('DBCC SQLPERF(LOGSPACE);')
#2
1
This does not directly answer the question, but it does answer the intent of the question: presumably, you want a simple way to find the current size of the log file:
这并没有直接回答这个问题,但它确实回答了问题的意图:大概,你想要一种简单的方法来查找日志文件的当前大小:
SELECT size*8192.0/1024.0/1024.0 as SizeMegabytes
FROM sys.database_files
WHERE type_desc = 'LOG'
-- If the log file size is 100 megabytes, returns "100".
The reason why we multiply by 8192 is that the page size in SQL server is 8192 bytes.
我们乘以8192的原因是SQL Server中的页面大小是8192字节。
The reason why we divide by 1024, then again by 1024, is to convert the size from bytes to megabytes.
我们除以1024,然后再除以1024的原因是将大小从字节转换为兆字节。