SQL Server: use parameter in CREATE DATABASE -
i want specify path data file , log file created in sql script using parameters. here wrote:
declare @datafilepath nvarchar(max) set @datafilepath = n'c:\programdata\gemcom\' declare @logfilepath 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, doesn't work. when try run in sql server management studio, got error
incorrect syntax near '@datafilepath'.
i wondering if intended possible?
thanks
you have use dynamic sql
select @sql = 'create database testdb on primary ( name = ''testdb_data'', filename = ' + quotename(@datafilepath) + ') log on ( name = ''testdb_log'', filename = ' + quotename(@logfilepath) + ')' exec (@sql)
Comments
Post a Comment