I want to specify the path where data file and log file is created in a SQL script using parameters. Here is what I wrote:
DECLARE @DataFilePath AS NVARCHAR(MAX)
SET @DataFilePath = N'C:\ProgramData\Gemcom\'
DECLARE @LogFilePath AS NVARCHAR(MAX)
SET @DataFilePath = N'C:\ProgramData\Gemcom\'
USE master
Go
CREATE DATABASE TestDB
ON
PRIMARY
( NAME = N'TestDB_Data', FILENAME = @DataFilePath )
LOG ON
( NAME = N'TestDB_Log', FILENAME = @LogFilePath )
GO
Unfortunately, this doesn't work. When I try to run it in SQL Server Management Studio, I got the error
Incorrect syntax near '@DataFilePath'.
I am wondering if what I intended to do is even possible?
Thanks