我在sql server中有一个增长限制,我为我的数据库设置了语句:
ALTER DATABASE [" + databaseName + "]
MODIFY FILE (NAME=dataFile,MAXSIZE = " + newSize + "MB)";
如何获取我为文件设置的大小?
答案 0 :(得分:4)
这样的东西?
select db.name as [db_name], mf.name, mf.max_size
from sys.master_files mf
JOIN sys.databases db ON mf.database_id = db.database_id
order by db.name
答案 1 :(得分:1)
在网上找到以下存储过程(Find SQL Server data and log files that are almost out of space)。
使用EXEC usp_get_db_files_near_maxsize <somepercentage>
运行它以查找所有数据库文件,包括数据和日志,这些文件仅在您设置了最大大小的文件的<somepercentage>
内填充。
CREATE PROCEDURE dbo.usp_get_db_files_near_maxsize (@nearMaxSizePct DECIMAL (5,1) = 10.0)
AS
BEGIN
SET NOCOUNT ON
CREATE TABLE ##ALL_DB_Files (
dbname SYSNAME,
fileid smallint,
groupid smallint,
[size] INT NOT NULL,
[maxsize] INT NOT NULL,
growth INT NOT NULL,
status INT,
perf INT,
[name] SYSNAME NOT NULL,
[filename] NVARCHAR(260) NOT NULL)
-- loop over all databases and collect the information from sysfiles
-- to the ALL_DB_Files tables using the sp_MsForEachDB system procedure
EXEC sp_MsForEachDB
@command1='use [$];Insert into ##ALL_DB_Files select db_name(), * from sysfiles',
@replacechar = '$'
-- output the results
SELECT
[dbname] AS DatabaseName,
[name] AS dbFileLogicalName,
[filename] AS dbFilePhysicalFilePath,
ROUND(size * CONVERT(FLOAT,8) / 1024,0) AS ActualSizeMB,
ROUND(maxsize * CONVERT(FLOAT,8) / 1024,0) AS MaxRestrictedSizeMB,
ROUND(maxsize * CONVERT(FLOAT,8) / 1024,0) - ROUND(size * CONVERT(FLOAT,8) / 1024,0) AS SpaceLeftMB
FROM ##ALL_DB_Files
WHERE maxsize > -1 AND -- skip db files that have no max size
([maxsize] - [size]) * 1.0 < 0.01 * @nearMaxSizePct * [maxsize] -- find db files within percentage
ORDER BY 6
DROP TABLE ##ALL_DB_Files
SET NOCOUNT OFF
END
GO