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:ProgramDataGemcom'
DECLARE @LogFilePath AS NVARCHAR(MAX)
SET @DataFilePath = N'C:ProgramDataGemcom'
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
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…