--1.查询机器名SELECT @@servername AS 机器名称--查询已安装的SQL实例名SELECT *FROM Sys.Servers--2.查询SQL安装路径DECLARE @installPath VARCHAR(200) EXEC MASTER.dbo.xp_regread 'HKEY_LOCAL_MACHINE', 'SOFTWARE\Microsoft\MSSQLSERVER\setup', 'SQLPath', @installPath OUTPUT SET @installPath = @installPath + '\data\' PRINT @installPath--3.得到SQL中的各种目录DECLARE @path VARCHAR(8000)--3.1得到当前数据库的数据文件路径SELECT @path = RTRIM(REVERSE(FILENAME))FROM sysfilesSELECT @path = REVERSE(SUBSTRING(@path, CHARINDEX('\', @path), 8000))SELECT 数据文件目录 = @path--3.2得到SQL安装时设置的数据文件路径SELECT @path = RTRIM(REVERSE(FILENAME))FROM MASTER..sysfilesWHERE NAME = 'master'SELECT @path = REVERSE(SUBSTRING(@path, CHARINDEX('\', @path), 8000))SELECT SQL数据文件目录 = @path--3.3根据安装路径得到默认的备份目录:SELECT @path = RTRIM(REVERSE(FILENAME))FROM MASTER..sysfilesWHERE NAME = 'master'SELECT @path = SUBSTRING(@path, CHARINDEX('\', @path) + 1, 8000), @path = REVERSE(SUBSTRING(@path, CHARINDEX('\', @path), 8000)) + 'BACKUP\'SELECT SQL数据默认备份目录 = @path
作者:a497785609 发表于2014-3-25 9:18:12
阅读:55 评论:0