I'm trying to create a generic script to create a database and want to pass the database name as a variable; but it's not working.
Here is my code so far
DECLARE @ID sysname;
SET @ID = 'test'
SET @ID = QUOTENAME(@ID)
CREATE DATABASE @ID
ON PRIMARY
( NAME = [' + @ID + '], FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\' +@ID+ '.mdf' , SIZE = 211968KB ,
MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
LOG ON
( NAME = [' + @ID + '_log'], FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\'@ID + '_log.ldf' , SIZE = 149696KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
which gives me the following error:
Incorrect syntax near '@ID'.