There's two schools of thoughts for this, one checks the registry and the other checks a location on the SQL Server (This is my preference). The logic is as follows:
DECLARE @mdfLocation nvarchar(256) = CAST(SERVERPROPERTY('InstanceDefaultDataPath') AS nvarchar(200));
DECLARE @ldfLocation nvarchar(256) = CAST(SERVERPROPERTY('InstanceDefaultLogPath') AS nvarchar(200));
Then all you need to do is update the SET logic to be as follows:
-- Define file paths for current database
SET @DataFilePath = @mdfLocation + @DatabaseName + '_Data.mdf'
SET @LogFilePath = @ldfLocation + @DatabaseName + '_Log.ldf'
There's two schools of thoughts for this, one checks the registry and the other checks a location on the SQL Server (This is my preference). The logic is as follows:
DECLARE @mdfLocation nvarchar(256) = CAST(SERVERPROPERTY('InstanceDefaultDataPath') AS nvarchar(200)); DECLARE @ldfLocation nvarchar(256) = CAST(SERVERPROPERTY('InstanceDefaultLogPath') AS nvarchar(200));
Then all you need to do is update the SET logic to be as follows: