December 24, 2014 at 6:07 am
This is my first forum post (I think). I've done a search and can't find any discussion on this.
I appreciate that there are many programmatic ways to achieve the same end result, but I'm wondering what is the core reason why in general we can't use variables in place of identifiers in DDL statements.
For example, it would seem intuitive and not obviously bad to be able to write statements like;
CREATE USER @newuser FOR LOGIN @newuser
I'm assuming it's to do with the mechanics of the parsing or binding in the query optimisation...?
December 24, 2014 at 8:59 am
You can't use variables to replace object names. That goes for DDL, DML, DCL or anything in T-SQL.
You could use dynamic SQL for this.
December 24, 2014 at 9:21 am
Ah yes, that's true.
It must be fundamental...I just can't see why.
the resolution of an object name can be done at runtime, as per the synonym functionality...it seems like a straightforward language extension to me, but I'm not a software architect.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply