Page 1 of 1

create database with parameters

Posted: Sat 01 Jan 2011 17:52
by RomanVD
I use TMSSQL.
SQL-

CREATE DATABASE :MY_DB

Executing-

MSSQL1.ParamByName('MY_DB').Value:='test';
MSSQL1.Execute;

It doesn't work and error occures - Exception class EMSError with message 'Incorrect syntax near '@P1'.'.

But without parameter using, for example - CREATE DATABASE test
- everything is OK.

Why?

Posted: Sun 02 Jan 2011 00:34
by RomanVD
In SQL profiler I see:

declare @p3 varchar(8000)
set @p3='test'
exec sp_executesql N'CREATE DATABASE @P1;',N'@P1 varchar(8000) OUTPUT',@p3 output
select @p3

And when try it in studio I get:

Msg 102, Level 15, State 1, Line 1
Incorrect syntax near '@P1'.

:?:

Posted: Sun 02 Jan 2011 12:20
by RomanVD
CREATE DATABASE does not support parameters.

That is the cause of my problem.

Posted: Mon 03 Jan 2011 16:09
by AndreyZ
Hello,

SQL Server doesn't support parameters in the DDL instructions, only in DML.